﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;

namespace DimensionalMeasurement
{
    class ImageProcesses
    {
        /// <summary>
        /// 测量线
        /// </summary>
        /// <param name="image">测量边缘所在的图像</param>
        /// <param name="windowHandle">测量结果显示的窗体</param>
        /// <param name="measureLine">测量线参数</param>
        /// <param name="rowBegin">线起始行坐标</param>
        /// <param name="colBegin">线起始列坐标</param>
        /// <param name="rowEnd">线末尾行坐标</param>
        /// <param name="colEnd">线末尾列坐标</param>
        public static void MeasureLine(HObject image, HWindow windowHandle, MeasureLine measureLine, out HTuple rowBegin, out HTuple colBegin, out HTuple rowEnd, out HTuple colEnd)
        {
            try
            {
                windowHandle.SetColor("green");
                windowHandle.SetLineWidth(1);
                windowHandle.DispRectangle2(measureLine.行坐标, measureLine.列坐标, measureLine.弧度, measureLine.半宽, measureLine.半高);
                //windowHandle.DispArrow(measureLine.行坐标 - Math.Sin(measureLine.弧度) * (measureLine.半宽 - 20), measureLine.列坐标 + Math.Cos(measureLine.弧度) * (measureLine.半宽 - 20), measureLine.行坐标 - Math.Sin(measureLine.弧度) * (measureLine.半宽 + 40), measureLine.列坐标 + Math.Cos(measureLine.弧度) * (measureLine.半宽 + 40), 2);

                HOperatorSet.GetImageSize(image, out HTuple width, out HTuple height);
                string transition, select;
                switch (measureLine.过渡方式)
                {
                    case Transition.白到黑: transition = "negative"; break;
                    case Transition.黑到白: transition = "positive"; break;
                    default: transition = "all"; break;
                }
                switch (measureLine.选择点)
                {
                    case Select.第一个点: select = "first"; break;
                    case Select.最后一个点: select = "last"; break;
                    default: select = "all"; break;
                }
                int count = Convert.ToInt32(measureLine.半高 * 2 / measureLine.步长);
                // double[] rowEdges = new double[count], columnEdges = new double[count];
                HTuple rowEdges = new HTuple(), columnEdges = new HTuple();
                for (int i = 0; i < count; ++i)
                {
                    HOperatorSet.GenMeasureRectangle2(measureLine.行坐标 - Math.Cos(measureLine.弧度) * (measureLine.半高 - i * measureLine.步长),
                        measureLine.列坐标 - Math.Sin(measureLine.弧度) * (measureLine.半高 - i * measureLine.步长),
                        measureLine.弧度, measureLine.半宽, measureLine.步长, width, height, "nearest_neighbor", out HTuple measureHandle);
                    HOperatorSet.MeasurePos(image, measureHandle, measureLine.滤波系数, measureLine.阈值, transition, select, out HTuple rowEdge, out HTuple columnEdge, out _, out _);
                    HOperatorSet.CloseMeasure(measureHandle);
                    rowEdges.Append(rowEdge);
                    columnEdges.Append(columnEdge);
                }
                if (rowEdges.Length > 1)
                {
                    HOperatorSet.GenContourPolygonXld(out HObject contour, rowEdges, columnEdges);
                    HOperatorSet.FitLineContourXld(contour, "tukey", -1, 0, 5, 2, out rowBegin, out colBegin, out rowEnd, out colEnd, out _, out _, out _);
                }
                else
                {
                    rowBegin = 0;
                    colBegin = 0;
                    rowEnd = 0;
                    colEnd = 0;
                }
                windowHandle.DispLine(rowBegin, colBegin, rowEnd, colEnd);
            }
            catch (Exception ex)
            {
                //Tool.LogForm("找边失败" + ex.ToString());
                rowBegin = 0;
                colBegin = 0;
                rowEnd = 0;
                colEnd = 0;
            }
        }

        /// <summary>
        /// 测量线,跟随
        /// </summary>
        /// <param name="image">测量边缘所在的图像</param>
        /// <param name="windowHandle">测量结果显示的窗体</param>
        /// <param name="row">测量区域行坐标</param>
        /// <param name="column">测量区域列坐标</param>
        /// <param name="angle">测量区域弧度</param>
        /// <param name="measureLine">测量线参数</param>
        /// <param name="rowBegin">线起始行坐标</param>
        /// <param name="colBegin">线起始列坐标</param>
        /// <param name="rowEnd">线末尾行坐标</param>
        /// <param name="colEnd">线末尾列坐标</param>
        public static void MeasureLine(HObject image, HWindow windowHandle, double row, double column, double angle, MeasureLine measureLine, out HTuple rowBegin, out HTuple colBegin, out HTuple rowEnd, out HTuple colEnd)
        {
            try
            {
                windowHandle.SetLineWidth(1);
                windowHandle.DispRectangle2(row, column, angle, measureLine.半宽, measureLine.半高);
                //windowHandle.DispArrow(row - Math.Sin(angle) * (measureLine.半宽 - 20), column + Math.Cos(angle) * (measureLine.半宽 - 20), row - Math.Sin(angle) * (measureLine.半宽 + 40), column + Math.Cos(angle) * (measureLine.半宽 + 40), 2);
                HOperatorSet.GetImageSize(image, out HTuple width, out HTuple height);
                string transition, select;
                switch (measureLine.过渡方式)
                {
                    case Transition.白到黑: transition = "negative"; break;
                    case Transition.黑到白: transition = "positive"; break;
                    default: transition = "all"; break;
                }
                switch (measureLine.选择点)
                {
                    case Select.第一个点: select = "first"; break;
                    case Select.最后一个点: select = "last"; break;
                    default: select = "all"; break;
                }
                int count = Convert.ToInt32(measureLine.半高 * 2 / measureLine.步长);
                HTuple rowEdges = new HTuple(), columnEdges = new HTuple();
                for (int i = 0; i < count; ++i)
                {
                    HOperatorSet.GenMeasureRectangle2(row - Math.Cos(angle) * (measureLine.半高 - i * measureLine.步长),
                        column - Math.Sin(angle) * (measureLine.半高 - i * measureLine.步长),
                        angle, measureLine.半宽, measureLine.步长, width, height, "nearest_neighbor", out HTuple measureHandle);
                    HOperatorSet.MeasurePos(image, measureHandle, measureLine.滤波系数, measureLine.阈值, transition, select, out HTuple rowEdge, out HTuple columnEdge, out _, out _);
                    HOperatorSet.CloseMeasure(measureHandle);
                    rowEdges.Append(rowEdge);
                    columnEdges.Append(columnEdge);
                }
                if (rowEdges.Length > 1)
                {
                    HOperatorSet.GenContourPolygonXld(out HObject contour, rowEdges, columnEdges);
                    HOperatorSet.FitLineContourXld(contour, "tukey", -1, 0, 5, 2, out rowBegin, out colBegin, out rowEnd, out colEnd, out _, out _, out _);
                }
                else
                {
                    rowBegin = 0;
                    colBegin = 0;
                    rowEnd = 0;
                    colEnd = 0;
                }
                windowHandle.SetColor("green");
                windowHandle.DispLine(rowBegin, colBegin, rowEnd, colEnd);
            }
            catch (Exception ex)
            {
                //Tool.LogForm("找边失败" + ex.ToString());
                rowBegin = 0;
                colBegin = 0;
                rowEnd = 0;
                colEnd = 0;
            }
        }




        /// <summary>
        /// 标定找边
        /// </summary>
        /// <param name="ho_Image">输入图像</param> 
        /// <param name="_htWindowHandle">输入显示窗口句柄</param>
        /// <param name="hv_Row1">输入矩形框的起始列</param>
        /// <param name="hv_Column1">输入矩形框起始行</param>
        /// <param name="hv_Row2">输入矩形框的终点列</param>
        /// <param name="hv_Column2">输入矩形框的终点行</param>       
        /// <param name="hv_Row3">输入矩形框的中心列</param>
        /// <param name="hv_Column3">输入矩形框的中心行</param>
        /// <param name="hv_Step">扫描间隔</param>
        /// <param name="hv_Threshold">最小边缘过渡(黑白阈值差)</param>
        /// <param name="hv_Transition">边缘提取方式,'negative'从白到黑,'positive'从黑到白,'all'都可以</param>
        /// <param name="hv_RowBegin">竖边的起始列</param>
        /// <param name="hv_ColBegin">竖的起始行</param>
        public void MeasureLine_Bd(HObject ho_Image, HTuple _htWindowHandle, HTuple hv_Row1, HTuple hv_Column1,
            HTuple hv_Row2, HTuple hv_Column2, HTuple hv_Row3, HTuple hv_Column3, HTuple hv_Step,
            HTuple hv_Threshold, HTuple hv_Transition, HTuple hv_Select,
            out HTuple hv_RowPoint,
            out HTuple hv_ColPoint)
        {
            HTuple hv_row_center = null, hv_col_center = null, hv_row_center1 = null;
            HTuple hv_col_center1 = null, hv_height = null, hv_width = null;
            HTuple hv_Cos = null, hv_Sin = null;
            HTuple hv_Width = null, hv_Height = null;
            HTuple hv_i = null, hv_MeasureHandle = new HTuple();
            HTuple hv_MeasureHandle1 = new HTuple(), hv_RowEdge = new HTuple();
            HTuple hv_ColumnEdge = new HTuple();
            HTuple hv_row1 = new HTuple(), hv_col1 = new HTuple();
            HTuple hv_RowEdge1 = new HTuple();
            HTuple hv_ColumnEdge1 = new HTuple();
            HTuple hv_row2 = new HTuple(), hv_col2 = new HTuple();
            HTuple hv_RL = null, hv_CL = null;
            HTuple hv_RL1 = null, hv_CL1 = null;
            HTuple hv_RowBegin = null;
            HTuple hv_ColBegin = null;
            HTuple hv_RowEnd = null;
            HTuple hv_ColEnd = null;
            HTuple hv_RowBegin1 = null;
            HTuple hv_ColBegin1 = null;
            HTuple hv_RowEnd1 = null;
            HTuple hv_ColEnd1 = null;
            HObject ho_Contour = null, ho_Contour1 = null;

            HOperatorSet.GenEmptyObj(out ho_Contour);
            HOperatorSet.GenEmptyObj(out ho_Contour1);


            //矩形的两个中心点
            hv_row_center = hv_Row3 - ((hv_Row2 - hv_Row1) / 2);
            hv_col_center1 = hv_Column3.Clone();

            hv_col_center = hv_Column3 + ((hv_Column2 - hv_Column1) / 2);
            hv_row_center1 = hv_Row3.Clone();

            //设置旋转矩形的宽高
            hv_height = (hv_Row2 - hv_Row1) / 4;
            hv_width = (hv_Column2 - hv_Column1) / 2;

            //竖边的旋转矩形              
            HOperatorSet.DispRectangle2(_htWindowHandle, hv_row_center, hv_col_center1,
               (new HTuple(0)).TupleRad(), hv_width, hv_height);

            //横边的旋转矩形
            HOperatorSet.DispRectangle2(_htWindowHandle, hv_row_center1, hv_col_center,
                (new HTuple(90)).TupleRad(), hv_width, hv_height);

            // HOperatorSet.SetLineWidth(_htWindowHandle, 1);

            HOperatorSet.TupleCos((new HTuple(0)).TupleRad(), out hv_Cos);
            HOperatorSet.TupleSin((new HTuple(0)).TupleRad(), out hv_Sin);
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);

            //竖边找边
            HTuple end_val37 = (hv_height * 2) / hv_Step;
            for (hv_i = 0; hv_i < end_val37; ++hv_i)
            {
                HOperatorSet.GenMeasureRectangle2(hv_row_center - (hv_Cos * (hv_height - hv_Step * hv_i)),
       hv_col_center1 - (hv_Sin * (hv_height - hv_Step * hv_i)), (new HTuple(0)).TupleRad()
       , hv_width, 0, hv_Width, hv_Height, "nearest_neighbor", out hv_MeasureHandle);


                HOperatorSet.MeasurePos(ho_Image, hv_MeasureHandle, 2, hv_Threshold, hv_Transition, hv_Select,
                    out hv_RowEdge, out hv_ColumnEdge, out _, out _);
                //将每个测量点赋值给row1,col1
                HOperatorSet.TupleConcat(hv_row1, hv_RowEdge, out hv_row1);
                hv_col1 = hv_col1.TupleConcat(hv_ColumnEdge);
                HOperatorSet.CloseMeasure(hv_MeasureHandle);
            }

            //横边找边
            HTuple end_val65 = (hv_height * 2) / hv_Step;
            for (hv_i = 0; hv_i < end_val65; ++hv_i)
            {
                HOperatorSet.GenMeasureRectangle2(hv_row_center1 - (hv_Sin * (hv_height - hv_Step * hv_i)),
    hv_col_center - (hv_Cos * (hv_height - hv_Step * hv_i)), (new HTuple(90)).TupleRad()
    , hv_width, 0, hv_Width, hv_Height, "nearest_neighbor", out hv_MeasureHandle1);

                HOperatorSet.MeasurePos(ho_Image, hv_MeasureHandle1, 2, hv_Threshold, hv_Transition, hv_Select,
                    out hv_RowEdge1, out hv_ColumnEdge1, out _, out _);
                //将每个测量点赋值给row2,col2
                hv_row2 = hv_RowEdge1.TupleConcat(hv_row2);
                hv_col2 = hv_ColumnEdge1.TupleConcat(hv_col2);
                HOperatorSet.CloseMeasure(hv_MeasureHandle1);
            }

            //计算结果点的行列个数
            HOperatorSet.TupleLength(hv_row1, out hv_RL);
            HOperatorSet.TupleLength(hv_col1, out hv_CL);
            HOperatorSet.TupleLength(hv_row2, out hv_RL1);
            HOperatorSet.TupleLength(hv_col2, out hv_CL1);

            //结果点的行个数或列个数>=2拟合,防止报错
            if ((int)((new HTuple((new HTuple(hv_RL.TupleGreaterEqual(2))).TupleOr((new HTuple(hv_CL.TupleGreaterEqual(
                 2))).TupleAnd(new HTuple(hv_RL1.TupleGreaterEqual(2)))))).TupleOr(new HTuple(hv_CL1.TupleGreaterEqual(
                 2)))) != 0)
            {
                //生成Contour，拟合竖边测量点
                ho_Contour.Dispose();
                HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_row1, hv_col1);
                HOperatorSet.FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, out hv_RowBegin,
                    out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out _, out _, out _);

                //拟合横边测量点
                ho_Contour1.Dispose();
                HOperatorSet.GenContourPolygonXld(out ho_Contour1, hv_row2, hv_col2);
                HOperatorSet.FitLineContourXld(ho_Contour1, "tukey", -1, 0, 5, 2, out hv_RowBegin1,
                    out hv_ColBegin1, out hv_RowEnd1, out hv_ColEnd1, out _, out _,
                    out _);
            }
            else
            {
                //置为-1,防止输出时画直线报错
                hv_RowBegin = -1;
                hv_ColBegin = -1;
                hv_RowEnd = -1;
                hv_ColEnd = -1;
                hv_RowBegin1 = -1;
                hv_ColBegin1 = -1;
                hv_RowEnd1 = -1;
                hv_ColEnd1 = -1;
            }
            HOperatorSet.SetColor(_htWindowHandle, "red");
            HOperatorSet.DispLine(_htWindowHandle, hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd);
            HOperatorSet.DispLine(_htWindowHandle, hv_RowBegin1, hv_ColBegin1, hv_RowEnd1, hv_ColEnd1);

            //横竖线交点
            HOperatorSet.IntersectionLl(hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd, hv_RowBegin1, hv_ColBegin1, hv_RowEnd1, hv_ColEnd1, out hv_RowPoint, out hv_ColPoint, out _);
            HOperatorSet.DispCross(_htWindowHandle, hv_RowPoint, hv_ColPoint, 30, 0.0);
            ho_Contour.Dispose();
            ho_Contour1.Dispose();
        }



        /// <summary>
        /// 计算像素比列
        /// </summary>
        /// <param name="ho_Image">输入图像</param> 
        /// <param name="_htWindowHandle">输入显示窗口句柄</param>
        /// <param name="hv_CenterRow">输入矩形框的行中心</param>
        /// <param name="hv_CenterCol">输入矩形框的列中心</param>
        /// <param name="hv_Phi">输入矩形框的角度</param>
        /// <param name="hv_Length1">输入矩形框的宽度</param>
        /// <param name="hv_Length2">输入矩形框的高度</param>
        /// <param name="hv_Step">扫描间隔</param>
        /// <param name="hv_Sigma">高期平滑度</param>
        /// <param name="hv_Threshold">最小边缘过渡</param>
        /// <param name="hv_Transition">边缘提取方式,'negative'从白到黑,'positive'从黑到白,'all'都可以</param>
        /// <param name="hv_Select">选取点方式,'first'第一个,'last'最后一个,'all'两者都有</param>
        /// <param name="hv_ShowSearchArea">是否显示搜索框</param>
        /// <param name="hv_ShowSearchLine">是否显示搜索线</param>
        /// <param name="hv_ShowResultPoints">是否显示结果点</param>
        /// <param name="hv_RowBegin"></param>边的起始行
        /// <param name="hv_ColBegin">边的起始列</param>
        /// <param name="hv_RowEnd">边的终点行</param>
        /// <param name="hv_ColEnd">边的终点列</param>
        public void rake_edge(HObject ho_Image, HTuple _htWindowHandle, HTuple hv_CenterRow, HTuple hv_CenterCol,
            HTuple hv_Phi, HTuple hv_Length1, HTuple hv_Length2, HTuple hv_Step, HTuple hv_Sigma,
            HTuple hv_Threshold, HTuple hv_Transition, HTuple hv_Select, HTuple hv_ShowSearchArea,
            HTuple hv_ShowSearchLine, HTuple hv_ShowResultPoints, out HTuple hv_RowBegin,
            out HTuple hv_ColBegin, out HTuple hv_RowEnd, out HTuple hv_ColEnd)
        {
            HObject ho_Arrow = null, ho_Rectangle = null, ho_Rectangle1 = null;
            HObject ho_Cross1 = null, ho_Contour = null;

            HTuple hv_RowLine = null, hv_ColLine = null;
            HTuple hv_Width = null, hv_Height = null, hv_Index = null;
            HTuple hv_MeasureHandle1 = new HTuple(), hv_RowEdge = new HTuple();
            HTuple hv_ColumnEdge = new HTuple(), hv_Amplitude = new HTuple();
            HTuple hv_Distance = new HTuple(), hv_Length = new HTuple();
            HTuple hv_RL = null, hv_CL = null, hv_Nr = new HTuple();
            HTuple hv_Nc = new HTuple(), hv_Dist = new HTuple();

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Cross1);
            HOperatorSet.GenEmptyObj(out ho_Contour);

            hv_RowBegin = new HTuple();
            hv_ColBegin = new HTuple();
            hv_RowEnd = new HTuple();
            hv_ColEnd = new HTuple();
            try
            {

                HOperatorSet.SetLineWidth(_htWindowHandle, 1);

                //初始化结果点的行列
                hv_RowLine = new HTuple();
                hv_ColLine = new HTuple();
                HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);

                //循环扫描点
                HTuple end_val41 = (hv_Length2 * 2) / hv_Step;
                HTuple step_val41 = 1;
                for (hv_Index = 0; hv_Index.Continue(end_val41, step_val41); hv_Index = hv_Index.TupleAdd(step_val41))
                {
                    //生成测量矩形,宽度为0,即为一条直线
                    HOperatorSet.GenMeasureRectangle2(hv_CenterRow - ((hv_Phi.TupleCos()) * (hv_Length2 - (hv_Step * hv_Index))),
                        hv_CenterCol - ((hv_Phi.TupleSin()) * (hv_Length2 - (hv_Step * hv_Index))), hv_Phi,
                        hv_Length1, 0, hv_Width, hv_Height, "nearest_neighbor", out hv_MeasureHandle1);
                    //是否显示搜索线
                    if ((int)(new HTuple(hv_ShowSearchLine.TupleEqual("TRUE"))) != 0)
                    {
                        ho_Rectangle1.Dispose();
                        HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_CenterRow - ((hv_Phi.TupleCos()
                            ) * (hv_Length2 - (hv_Step * hv_Index))), hv_CenterCol - ((hv_Phi.TupleSin()
                            ) * (hv_Length2 - (hv_Step * hv_Index))), hv_Phi, hv_Length1, 0);
                        HOperatorSet.SetColor(_htWindowHandle, "blue");

                        //HOperatorSet.DispObj(ho_Rectangle1, _htWindowHandle);

                    }

                    //测量点
                    HOperatorSet.MeasurePos(ho_Image, hv_MeasureHandle1, hv_Sigma, hv_Threshold,
                        hv_Transition, hv_Select, out hv_RowEdge, out hv_ColumnEdge, out hv_Amplitude,
                        out hv_Distance);
                    HOperatorSet.CloseMeasure(hv_MeasureHandle1);
                    //是否显示结果点
                    if ((int)(new HTuple(hv_ShowResultPoints.TupleEqual("TRUE"))) != 0)
                    {
                        HOperatorSet.TupleLength(hv_RowEdge, out hv_Length);
                        if ((int)(new HTuple(hv_Length.TupleGreater(0))) != 0)
                        {
                            hv_RowLine = hv_RowLine.TupleConcat(hv_RowEdge);
                            hv_ColLine = hv_ColLine.TupleConcat(hv_ColumnEdge);
                            //生成十字架
                            ho_Cross1.Dispose();
                            HOperatorSet.GenCrossContourXld(out ho_Cross1, hv_RowEdge, hv_ColumnEdge,
                                2, 0);
                            HOperatorSet.SetColor(_htWindowHandle, "yellow");

                            HOperatorSet.DispObj(ho_Cross1, _htWindowHandle);

                        }
                    }

                }
                //计算结果点的行列个数
                HOperatorSet.TupleLength(hv_RowLine, out hv_RL);
                HOperatorSet.TupleLength(hv_RowLine, out hv_CL);
                //结果点的行个数或列个数>=2拟合,防止报错
                if ((int)((new HTuple(hv_RL.TupleGreater(1))).TupleOr(new HTuple(hv_CL.TupleGreater(
                    1)))) != 0)
                {
                    //生成Contour
                    ho_Contour.Dispose();
                    HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowLine, hv_ColLine);
                    //拟合直线,参数可以更改或改成接口
                    HOperatorSet.FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, out hv_RowBegin,
                        out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc,
                        out hv_Dist);
                    //HOperatorSet.DispObj(ho_Image, _htWindowHandle);
                    //HOperatorSet.SetColor(_htWindowHandle, "red");
                    //HOperatorSet.DispLine(_htWindowHandle, hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd);
                }
                else
                {
                    //置为-1,防止输出时画直线报错
                    hv_RowBegin = -1;
                    hv_ColBegin = -1;
                    hv_RowEnd = -1;
                    hv_ColEnd = -1;
                }
                HOperatorSet.SetColor(_htWindowHandle, "red");

                HOperatorSet.DispLine(_htWindowHandle, hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd);
                ho_Arrow.Dispose();
                ho_Rectangle.Dispose();
                ho_Rectangle1.Dispose();
                ho_Cross1.Dispose();
                ho_Contour.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {
                hv_RowBegin = -1;
                hv_ColBegin = -1;
                hv_RowEnd = -1;
                hv_ColEnd = -1;
                ho_Arrow.Dispose();
                ho_Rectangle.Dispose();
                ho_Rectangle1.Dispose();
                ho_Cross1.Dispose();
                ho_Contour.Dispose();
            }
        }








        /// <summary>
        /// 极耳打折检测
        /// </summary>
        /// <param name="ho_Image"></param>
        /// <param name="hv_WindowHandle"></param>
        /// <param name="param"></param>
        /// <param name="hv_Result"></param>
        public static void JeDetect(HObject ho_Image, HWindow hv_WindowHandle, double[] param, out string hv_Result)
        {
            #region 配置参数
            //检测框Row
            double row = param[0];
            //检测框COl
            double col = param[1];
            ////检测框弧度
            //double angle = param[2];
            //像素比
            double PixelRatio = param[2];
            //最小灰度值
            double JEGrayMin = param[3];
            //最大灰度值
            double JEGrayMax = param[4];
            //标准面积
            double JEAreaStandard = param[5];
            //面积容差
            double JEAreaRange = param[6];
            //过滤干扰面积
            double JEFiltrationArea = param[7];
            //X内缩
            double JEColumnErosion = param[8];
            //Y内缩
            double JERowErosion = param[9];
            //矩形度
            double JERectangularity = param[10];
            //缺口最小灰度值
            int JEGapGrayMin = (int)param[11];
            //缺口最大灰度值
            int JEGapGrayMax = (int)param[12];
            //缺口面积上限
            double JEGapAreaMax = param[13];
            //检测框高
            double JEHeight = param[14];
            //检测框宽
            double JEWidth = param[15];

            HTuple hv_Area = null;
            HObject ho_Rectangle, ho_ImageReduced;
            HObject ho_Regions, ho_ConnectedRegions, ho_SelectedRegions;
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_Regions);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out HObject ho_ErosionRectangle);
            HOperatorSet.GenEmptyObj(out HObject ho_Threshold);
            #endregion
            //获取图像高度，进行打印字体
            // HOperatorSet.GetImageSize(ho_Image, out _, out HTuple height);
            try
            {
                hv_Result = "";
                HOperatorSet.GenRectangle2(out ho_Rectangle, row, col, 0, JEWidth / PixelRatio / 2, JEHeight / PixelRatio / 2);
                hv_WindowHandle.SetColor("blue");
                hv_WindowHandle.DispObj(ho_Rectangle);
                HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced);
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, JEGrayMin, JEGrayMax);
                // 内缩为0就不进行内缩
                if (JEColumnErosion != 0 && JERowErosion != 0)
                {
                    HOperatorSet.ErosionRectangle1(ho_Regions, out ho_ErosionRectangle, JEColumnErosion / PixelRatio, JERowErosion / PixelRatio);
                    HOperatorSet.Connection(ho_ErosionRectangle, out ho_ConnectedRegions);
                }
                else
                {
                    HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                }
                HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area", "and", JEFiltrationArea / PixelRatio / PixelRatio, 999999999999);//剔除一些干扰点 
                HOperatorSet.AreaCenter(ho_SelectedRegions, out hv_Area, out _, out _);
                HOperatorSet.TupleLength(hv_Area, out HTuple hv_Length);


                //是否存在极耳判断
                if (!(hv_Length >= 1))
                {
                    hv_Result = "极耳打折";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    //  hv_WindowHandle.SetTposition(height.I - 300, 1);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString(" 未检测到极耳");
                    return;
                }
                double d_Area = (hv_Area * PixelRatio * PixelRatio); //计算极耳面积
                                                                     //面积是否超限判断                                                   
                if (d_Area < JEAreaStandard - JEAreaRange)
                {
                    hv_Result = "极耳打折";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    hv_WindowHandle.DispObj(ho_SelectedRegions);
                    // hv_WindowHandle.SetTposition(height.I - 300, 1);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString($"极耳打折NG：{d_Area:F2}");
                    return;
                }
                if (d_Area > JEAreaStandard + JEAreaRange)
                {
                    hv_Result = "极耳余料";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    hv_WindowHandle.DispObj(ho_SelectedRegions);
                    //  hv_WindowHandle.SetTposition(height.I - 300, 1);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString($"极耳余料NG：{d_Area:F2}");
                    return;
                }

                //缺口面积不等于0，进行缺口检测
                if (JEGapAreaMax != 0)
                {
                    HOperatorSet.ShapeTrans(ho_SelectedRegions, out HObject regionTrans, "rectangle2");
                    HOperatorSet.ErosionRectangle1(regionTrans, out HObject ErosionRectangle, JEColumnErosion / PixelRatio, JERowErosion / PixelRatio);
                    HOperatorSet.ReduceDomain(ho_ImageReduced, ErosionRectangle, out HObject ho_ReduceDomain);
                    HOperatorSet.Threshold(ho_ReduceDomain, out ho_Threshold, JEGapGrayMin, JEGapGrayMax);
                    HOperatorSet.AreaCenter(ho_Threshold, out HTuple hv_Area1, out _, out _);
                    //缺口面积
                    double d_Area1 = hv_Area1 * PixelRatio * PixelRatio;
                    //缺口面积是否超限判断
                    if (d_Area1 > JEGapAreaMax)
                    {
                        hv_Result = "极耳打折";//结果赋值NG
                        hv_WindowHandle.SetColor("red");
                        hv_WindowHandle.DispObj(ho_Threshold);
                        //hv_WindowHandle.SetTposition(height.I - 300, 1);
                        HOperatorSet.NewLine(hv_WindowHandle);
                        hv_WindowHandle.WriteString($"极耳缺口NG:{d_Area1:F2}");
                        return;
                    }
                    //矩形度设定值不等于0，进行矩形度检测
                    if (JERectangularity != 0)
                    {
                        HOperatorSet.Rectangularity(ho_SelectedRegions, out HTuple hv_rectangularity);
                        //矩形度是否超限判断
                        if (hv_rectangularity < JERectangularity)
                        {
                            hv_Result = "极耳打折";//结果赋值NG
                            hv_WindowHandle.SetColor("red");
                            hv_WindowHandle.DispObj(ho_SelectedRegions);
                            // hv_WindowHandle.SetTposition(height.I - 300, 1);
                            HOperatorSet.NewLine(hv_WindowHandle);
                            hv_WindowHandle.WriteString($"极耳矩形相似度NG:{hv_rectangularity.D:F2}");
                        }
                    }
                }
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Regions.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ErosionRectangle.Dispose();
                ho_Threshold.Dispose();
            }
            catch (Exception)
            {
                hv_Result = "极耳打折";//结果赋值NG
                hv_WindowHandle.SetColor("red");
                HOperatorSet.NewLine(hv_WindowHandle);
                // hv_WindowHandle.SetTposition(height.I - 300, 1);
                hv_WindowHandle.WriteString($"极耳检测异常，检查参数是否正确");
                ho_Rectangle.Dispose();
                ho_ImageReduced.Dispose();
                ho_Regions.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ErosionRectangle.Dispose();
                ho_Threshold.Dispose();
            }
        }

        /// <summary>
        /// 缺角检测-矩形框
        /// </summary>
        /// <param name="image"></param>
        /// <param name="hw"></param>
        /// <param name="triangle">三角形检测框</param>
        /// <param name="param">参数</param>
        /// <param name="BevelArea">面积</param>
        public static void BevelDetect(HObject image, HWindow hw, bool triangle, double[] param, out double BevelArea)
        {
            //极片角点坐标
            double row = param[0];
            double col = param[1];
            //缺角最小灰度值
            double BevelGrayMin = param[2];
            //缺角框大小
            double BevelFrame = param[3];
            //像素比
            double PixelRatio = param[4];
            //补偿值
            double Compensate = param[5];
            //偏移
            double RowSkew = param[6];
            double ColSkew = param[7];
            //横边
            double rowBegin1 = param[8];
            double colBegin1 = param[9];
            double rowEnd1 = param[10];
            double colEnd1 = param[11];
            //竖边
            double rowBegin2 = param[12];
            double colBegin2 = param[13];
            double rowEnd2 = param[14];
            double colEnd2 = param[15];

            HOperatorSet.GenEmptyObj(out HObject ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out HObject ho_iamgeReduced);
            HOperatorSet.GenEmptyObj(out HObject ho_region);
            HOperatorSet.GenEmptyObj(out HObject ho_regionErosion);

            if (!triangle)
            {
                ho_Rectangle2.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle2, row + RowSkew / PixelRatio, col + ColSkew / PixelRatio, 0, BevelFrame / PixelRatio / 2, BevelFrame / PixelRatio / 2);
                hw.SetColor("blue");
                hw.DispRectangle2(row + RowSkew / PixelRatio, col + ColSkew / PixelRatio, 0, BevelFrame / PixelRatio / 2, BevelFrame / PixelRatio / 2);
            }
            else
            {
                //横边角度
                double LateralEdgeAngle = Math.Atan2(rowEnd1 - rowBegin1, colEnd1 - colBegin1);
                double Row = Math.Abs(Math.Sin(LateralEdgeAngle) * BevelFrame / PixelRatio);
                double Col = Math.Abs(Math.Cos(LateralEdgeAngle) * BevelFrame / PixelRatio);
                double LateralEdgeRow = row + Row;
                double LateralEdgeCol = col - Col;
                if (row < rowBegin1)
                {
                    LateralEdgeRow = row - Row;
                }
                if (col < colBegin1)
                {
                    LateralEdgeCol = col + Col;
                }
                //竖边角度
                double VerticalEdgeAngle = Math.Atan2(rowEnd2 - rowBegin2, colEnd2 - colBegin2);
                Row = Math.Abs(Math.Sin(VerticalEdgeAngle) * BevelFrame / PixelRatio);
                Col = Math.Abs(Math.Cos(VerticalEdgeAngle) * BevelFrame / PixelRatio);
                double VerticalRow = row - Row;
                double VerticalCol = col - Col;
                if (row < rowBegin2)
                {
                    VerticalRow = row + Row;
                }
                if (col < colBegin2)
                {
                    VerticalCol = col + Col;
                }

                double[] rows = { row, LateralEdgeRow, VerticalRow }; double[] columns = { col, LateralEdgeCol, VerticalCol };
                //图像处理
                ho_Rectangle2.Dispose();
                HOperatorSet.GenRegionPolygonFilled(out ho_Rectangle2, rows, columns);
                hw.SetColor("blue");
                hw.DispObj(ho_Rectangle2);

            }
            ho_iamgeReduced.Dispose();
            HOperatorSet.ReduceDomain(image, ho_Rectangle2, out ho_iamgeReduced);
            ho_region.Dispose();
            HOperatorSet.Threshold(ho_iamgeReduced, out ho_region, BevelGrayMin, 255);
            ho_regionErosion.Dispose();
            HOperatorSet.ErosionRectangle1(ho_region, out ho_regionErosion, 2, 2);
            HOperatorSet.AreaCenter(ho_regionErosion, out HTuple hv_area, out _, out _);
            BevelArea = Math.Round((hv_area * PixelRatio * PixelRatio).D + Compensate, 3);

            ho_Rectangle2.Dispose();
            ho_iamgeReduced.Dispose();
            ho_region.Dispose();
            ho_regionErosion.Dispose();
        }


        /// <summary>
        /// 极耳打折检测
        /// </summary>
        /// <param name="ho_Image"></param>
        /// <param name="hv_WindowHandle"></param>
        /// <param name="param"></param>
        /// <param name="hv_Result"></param>
        public static void JeDetectP(HObject ho_Image, HWindow hv_WindowHandle, double[] param, HTuple JeRow, HTuple JeCol, out string hv_Result, HTuple Row = null, HTuple Col = null)
        {
            #region 配置参数
            //检测框Row
            double row = param[0];
            //检测框COl
            double col = param[1];
            //像素比
            double PixelRatio = param[2];
            //最小灰度值
            double JEGrayMin = param[3];
            //最大灰度值
            double JEGrayMax = param[4];
            //标准面积
            double JEAreaStandard = param[5];
            //面积容差
            double JEAreaRange = param[6];
            //余料面积
            double JeOddmentsArea = param[7];
            //X内缩
            double JEColumnErosion = param[8];
            //Y内缩
            double JERowErosion = param[9];
            //矩形度
            double JERectangularity = param[10];
            //缺口最小灰度值
            int JEGapGrayMin = (int)param[11];
            //缺口最大灰度值
            int JEGapGrayMax = (int)param[12];
            //缺口面积上限
            double JEGapAreaMax = param[13];
            //检测框高
            double JEHeight = param[14];
            //检测框宽
            double JEWidth = param[15];
            //上圆弧缺口面积上限
            double ArcArea = param[16];
            //下圆弧面积上限
            double ArcArea_R = param[17];
            //下圆弧面积下限
            double ArcAreamin_R = param[19];

            HTuple hv_Area = null;
            HObject ho_Rectangle, ho_ImageReduced, ho_RectangleLArc, ho_RectangleRArc, ho_ImageReducedLArc, ho_ImageReducedRArc;
            HObject ho_Regions, ho_ConnectedRegions, ho_SelectedRegions, ho_RegionsLArc, ho_RegionsRArc;
            HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_RectangleLArc); HOperatorSet.GenEmptyObj(out ho_RectangleRArc);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImageReducedLArc);
            HOperatorSet.GenEmptyObj(out ho_ImageReducedRArc);
            HOperatorSet.GenEmptyObj(out ho_Regions); HOperatorSet.GenEmptyObj(out ho_RegionsLArc); HOperatorSet.GenEmptyObj(out ho_RegionsRArc);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out HObject ho_ErosionRectangle);
            HOperatorSet.GenEmptyObj(out HObject ho_Threshold);

            #endregion

            try
            {
                hv_Result = "ok";
                HOperatorSet.GenRectangle2(out ho_Rectangle, row, col, 0, JEWidth / PixelRatio / 2, JEHeight / PixelRatio / 2);
                hv_WindowHandle.SetColor("blue");
                hv_WindowHandle.DispObj(ho_Rectangle);
                HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced);
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, JEGrayMin, JEGrayMax);
                // 内缩为0就不进行内缩
                if (JEColumnErosion != 0 && JERowErosion != 0)
                {
                    HOperatorSet.ErosionRectangle1(ho_Regions, out ho_ErosionRectangle, JEColumnErosion / PixelRatio, JERowErosion / PixelRatio);
                    //HOperatorSet.DilationRectangle1(ho_ErosionRectangle, out HObject ho_ErosionRectangle1, JEColumnErosion / PixelRatio, JERowErosion / PixelRatio);
                    HOperatorSet.Connection(ho_ErosionRectangle, out ho_ConnectedRegions);
                }
                else
                {
                    HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                }
                HOperatorSet.SelectShape(ho_ConnectedRegions, out HObject ho_SelectedRegion, "area", "and", 500, 999999999999);//剔除一些干扰点 
                HOperatorSet.Union1(ho_SelectedRegion, out ho_SelectedRegions);
                HOperatorSet.AreaCenter(ho_SelectedRegions, out hv_Area, out _, out _);
                HOperatorSet.TupleLength(hv_Area, out HTuple hv_Length);


                //是否存在极耳判断
                if (!(hv_Length >= 1))
                {
                    hv_Result = "极耳打折";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    //  hv_WindowHandle.SetTposition(height.I - 300, 1);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString(" 未检测到极耳");
                    return;
                }
                double d_Area = (hv_Area * PixelRatio * PixelRatio); //计算极耳面积
                //面积是否超限判断                                                   
                if ((d_Area < JEAreaStandard - JEAreaRange) /*|| (d_Area > JEAreaStandard + JEAreaRange)*/)
                {
                    hv_Result = "极耳打折";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    hv_WindowHandle.DispObj(ho_SelectedRegions);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString($"极耳打折NG：{d_Area:F2}");
                    //return;
                }

                if (d_Area > JEAreaStandard + JEAreaRange)
                {
                    hv_Result = "极耳余料";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    hv_WindowHandle.DispObj(ho_SelectedRegions);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString($"极耳余料NG：{d_Area:F2}");
                    //return;
                }


                //矩形度设定值不等于0，进行矩形度检测
                if (JERectangularity != 0)
                {
                    HOperatorSet.Rectangularity(ho_SelectedRegions, out HTuple hv_rectangularity);
                    //矩形度是否超限判断
                    if (hv_rectangularity < JERectangularity)
                    {
                        hv_Result = "极耳打折";//结果赋值NG
                        hv_WindowHandle.SetColor("red");
                        hv_WindowHandle.DispObj(ho_SelectedRegions);
                        // hv_WindowHandle.SetTposition(height.I - 300, 1);
                        HOperatorSet.NewLine(hv_WindowHandle);
                        hv_WindowHandle.WriteString($"极耳矩形相似度NG:{hv_rectangularity.D:F2}"); /*return;*/
                    }
                }

                HOperatorSet.GenEmptyObj(out HObject ho_Region);
                HOperatorSet.GenEmptyObj(out HObject ErosionRegion);
                HOperatorSet.GenEmptyObj(out HObject imageReducd);
                HOperatorSet.GenEmptyObj(out HObject ho_Region1);
                HObject ho_RegionClosingL = new HObject(), ho_RegionClosingR = new HObject();
                if (JEGapAreaMax != 0 /*&& param[21] != 0*/)//缺口面积不等于0，进行缺口检测
                {

                    //极耳检测框上边与极耳右竖边交点
                    HOperatorSet.IntersectionLl(row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), JeRow[6], JeCol[6], JeRow[7], JeCol[7], out HTuple intersectionRow1, out HTuple intersectionCol1, out _);
                    //极耳右竖边与极耳横边交点
                    HOperatorSet.IntersectionLl(JeRow[6], JeCol[6], JeRow[7], JeCol[7], JeRow[2], JeCol[2], JeRow[3], JeCol[3], out HTuple intersectionRow2, out HTuple intersectionCol2, out _);
                    //极耳横边与极耳左竖边交点
                    HOperatorSet.IntersectionLl(JeRow[2], JeCol[2], JeRow[3], JeCol[3], JeRow[4], JeCol[4], JeRow[5], JeCol[5], out HTuple intersectionRow3, out HTuple intersectionCol3, out _);
                    //极耳左竖边与极耳检测框上边交点
                    HOperatorSet.IntersectionLl(JeRow[4], JeCol[4], JeRow[5], JeCol[5], row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), out HTuple intersectionRow4, out HTuple intersectionCol4, out _);
                    double[] Gaprow = new double[] { intersectionRow1, intersectionRow2, intersectionRow3, intersectionRow4 }, Gapcol = new double[] { intersectionCol1, intersectionCol2, intersectionCol3, intersectionCol4 };
                    ho_Region.Dispose();
                    HOperatorSet.GenRegionPolygonFilled(out ho_Region, Gaprow, Gapcol);
                    HObject circleL = new HObject(), circleR = new HObject(), regionDifferenceL = new HObject(), regionDifferenceR = new HObject();
                    HObject hObject = new HObject();
                    HOperatorSet.GenCircle(out circleL, intersectionRow2, intersectionCol2, 3 / PixelRatio);
                    HOperatorSet.GenCircle(out circleR, intersectionRow3, intersectionCol3, 3 / PixelRatio);
                    if (ArcArea_R != 0)
                    {
                        HOperatorSet.Difference(ho_Region, circleL, out regionDifferenceL);
                        HOperatorSet.Difference(regionDifferenceL, circleR, out regionDifferenceR);
                        HOperatorSet.ErosionRectangle1(regionDifferenceR, out ErosionRegion, 9, 9);
                    }
                    else
                    {
                        ErosionRegion.Dispose();
                        HOperatorSet.ErosionRectangle1(ho_Region, out ErosionRegion, 9, 9);
                    }
                    imageReducd.Dispose();
                    HOperatorSet.ReduceDomain(ho_Image, ErosionRegion, out imageReducd);
                    ho_Region1.Dispose();
                    HOperatorSet.Threshold(imageReducd, out ho_Region1, JEGapGrayMin, JEGapGrayMax);
                    HOperatorSet.Connection(ho_Region1, out HObject connectedRegions);
                    HOperatorSet.SelectShape(connectedRegions, out HObject ho_SelectedRegion1, "area", "and", 30, 999999999999);//剔除一些干扰点 
                    HOperatorSet.DilationRectangle1(ho_SelectedRegion1, out HObject regionDilation, 1, 1);
                    HOperatorSet.AreaCenter(regionDilation, out HTuple area, out _, out _);
                    if (area.Length > 0)
                    {
                        double areaPhy = area * PixelRatio * PixelRatio;//缺口面积
                        if (areaPhy > JEGapAreaMax)//缺口面积是否超限判断
                        {
                            hv_WindowHandle.SetColor("red");
                            hv_WindowHandle.DispObj(regionDilation);
                            HOperatorSet.NewLine(hv_WindowHandle);
                            hv_WindowHandle.WriteString($"极耳缺口NG：{areaPhy:F2}-极耳打折");
                            hv_Result = "极耳打折";
                            //return;
                        }
                    }
                    if (ArcArea_R != 0)
                    {
                        HOperatorSet.ReduceDomain(ho_Image, circleL, out HObject imageReducedL);
                        HOperatorSet.Threshold(imageReducedL, out HObject regionL, 200, 255);
                        HOperatorSet.AreaCenter(regionL, out HTuple area1L, out _, out _);
                        double L = area1L * PixelRatio * PixelRatio;
                        if (L > ArcArea_R || L < ArcAreamin_R)
                        {
                            hv_WindowHandle.SetColor("red");
                            hv_WindowHandle.DispObj(regionL);
                            HOperatorSet.NewLine(hv_WindowHandle);
                            hv_WindowHandle.WriteString($"极耳左下圆弧NG：{L:F2}-极耳打折");
                            hv_Result = "极耳打折";
                        }

                        HOperatorSet.ReduceDomain(ho_Image, circleR, out HObject imageReducedR);
                        HOperatorSet.Threshold(imageReducedR, out HObject regionR, 200, 255);
                        HOperatorSet.AreaCenter(regionR, out HTuple area1R, out _, out _);
                        double R = area1R * PixelRatio * PixelRatio;
                        if (R > ArcArea_R || R < ArcAreamin_R)
                        {
                            hv_WindowHandle.SetColor("red");
                            hv_WindowHandle.DispObj(regionR);
                            HOperatorSet.NewLine(hv_WindowHandle);
                            hv_WindowHandle.WriteString($"极耳右下圆弧NG：{R:F2}-极耳打折");
                            hv_Result = "极耳打折";
                        }
                    }


                    if (ArcArea != 0)
                    {
                        //极片左横边与极耳左竖边交点
                        HOperatorSet.IntersectionLl(Row[0], Col[0], Row[1], Col[1], JeRow[4], JeCol[4], JeRow[5], JeCol[5], out HTuple hv_Row_JD, out HTuple hv_Column_JD, out _);

                        //生成圆区域，检测黑色区域，膨胀，腐蚀，连接破损断裂处弧-----0711--------------*
                        HOperatorSet.GenCircle(out HObject ho_Circle0, hv_Row_JD, hv_Column_JD, 260);
                        HOperatorSet.ReduceDomain(ho_Image, ho_Circle0, out HObject ho_ImageReduced0L
                            );

                        HOperatorSet.BinaryThreshold(ho_ImageReduced0L, out HObject ho_Region0L, "max_separability",
                            "dark", out _);
                        HOperatorSet.OpeningCircle(ho_Region0L, out HObject ho_Region1L, 50);
                        HOperatorSet.ClosingCircle(ho_Region1L, out ho_RegionClosingL, 110);
                        //HOperatorSet.GenContourRegionXld(ho_RegionClosingL, out  ho_ContoursL, "border");
                        hv_WindowHandle.SetColor("blue");
                        HOperatorSet.ErosionRectangle1(ho_RegionClosingL, out ho_RegionClosingL, 6, 6);
                        HOperatorSet.DispObj(ho_RegionClosingL, hv_WindowHandle);
                        //破损面积*
                        hv_Area.Dispose();
                        hv_Area = 0;
                        HOperatorSet.ReduceDomain(ho_Image, ho_RegionClosingL, out HObject ho_ImageReducedL
                            );
                        HOperatorSet.Threshold(ho_ImageReducedL, out HObject ho_RegionL, param[20],
                            255);
                        HOperatorSet.Connection(ho_RegionL, out HObject ho_ConnectedRegionsL);
                        HOperatorSet.SelectShape(ho_ConnectedRegionsL, out HObject ho_SelectedRegionsL, "area",
                            "and", 3, 9999999);
                        hv_Area.Dispose();
                        HOperatorSet.AreaCenter(ho_SelectedRegionsL, out hv_Area, out _, out _);
                        {
                            HTuple ExpTmpOutVar_0;
                            HOperatorSet.TupleSum(hv_Area, out ExpTmpOutVar_0);
                            hv_Area.Dispose();
                            hv_Area = ExpTmpOutVar_0;
                        }
                        if (hv_Area > 0)
                        {
                            double hv_AreaL = hv_Area * PixelRatio * PixelRatio;
                            if (hv_AreaL > ArcArea)
                            {
                                hv_WindowHandle.SetColor("red");
                                hv_WindowHandle.DispObj(ho_SelectedRegionsL);
                                HOperatorSet.NewLine(hv_WindowHandle);
                                hv_WindowHandle.WriteString($"极耳左上圆弧NG：{hv_AreaL:F4}-极耳打折");
                                hv_Result = "极耳打折";
                            }
                        }


                        //极片右横边与极耳右竖边交点
                        HOperatorSet.IntersectionLl(Row[9], Col[9], Row[10], Col[10], JeRow[6], JeCol[6], JeRow[7], JeCol[7], out hv_Row_JD, out hv_Column_JD, out _);
                        //生成圆区域，检测黑色区域，膨胀，腐蚀，连接破损断裂处弧-----0711--------------*
                        HOperatorSet.GenCircle(out ho_Circle0, hv_Row_JD, hv_Column_JD, 260);
                        HOperatorSet.ReduceDomain(ho_Image, ho_Circle0, out ho_ImageReduced0L
                            );

                        HOperatorSet.BinaryThreshold(ho_ImageReduced0L, out ho_Region0L, "max_separability",
                            "dark", out _);
                        HOperatorSet.OpeningCircle(ho_Region0L, out ho_Region1L, 50);
                        HOperatorSet.ClosingCircle(ho_Region1L, out ho_RegionClosingR, 110);
                        //HOperatorSet.GenContourRegionXld(ho_RegionClosingL, out ho_ContoursR, "border");
                        hv_WindowHandle.SetColor("blue");
                        HOperatorSet.DispObj(ho_RegionClosingR, hv_WindowHandle);
                        //破损面积*
                        hv_Area.Dispose();
                        hv_Area = 0;
                        ho_ImageReducedL.Dispose();
                        HOperatorSet.ErosionRectangle1(ho_RegionClosingR, out ho_RegionClosingR, 6, 6);
                        HOperatorSet.ReduceDomain(ho_Image, ho_RegionClosingR, out ho_ImageReducedL
                            );

                        HOperatorSet.Threshold(ho_ImageReducedL, out ho_RegionL, param[20],
                            255);
                        HOperatorSet.Connection(ho_RegionL, out ho_ConnectedRegionsL);
                        HOperatorSet.SelectShape(ho_ConnectedRegionsL, out ho_SelectedRegionsL, "area",
                            "and", 3, 99999);
                        hv_Area.Dispose();
                        HOperatorSet.AreaCenter(ho_SelectedRegionsL, out hv_Area, out _, out _);
                        {
                            HTuple ExpTmpOutVar_0;
                            HOperatorSet.TupleSum(hv_Area, out ExpTmpOutVar_0);
                            hv_Area.Dispose();
                            hv_Area = ExpTmpOutVar_0;
                        }
                        if (hv_Area > 0)
                        {
                            double hv_AreaL = hv_Area * PixelRatio * PixelRatio;
                            if (hv_AreaL > ArcArea)
                            {
                                hv_WindowHandle.SetColor("red");
                                hv_WindowHandle.DispObj(ho_SelectedRegionsL);
                                HOperatorSet.NewLine(hv_WindowHandle);
                                hv_WindowHandle.WriteString($"极耳右上圆弧NG：{hv_AreaL:F4}-极耳打折");
                                hv_Result = "极耳打折";
                            }
                        }

                    }
                }

                HOperatorSet.GenEmptyObj(out HObject ho_DifferenceRegion);
                HOperatorSet.GenEmptyObj(out HObject ho_ErosionRegion);
                HOperatorSet.GenEmptyObj(out HObject ho_imageReducd);
                HOperatorSet.GenEmptyObj(out HObject Threshold);
                if (JeOddmentsArea != 0 /*&& param[21] != 0*/)
                {
                    ho_DifferenceRegion.Dispose();
                    HOperatorSet.Difference(ho_Rectangle, ho_Region, out ho_DifferenceRegion);
                    HOperatorSet.ErosionRectangle1(ho_DifferenceRegion, out ho_DifferenceRegion, 0.5 / PixelRatio, 0.5 / PixelRatio);


                    if (ArcArea != 0)
                    {
                        HOperatorSet.Difference(ho_DifferenceRegion, ho_RegionClosingL, out HObject ho_DifferenceRegionL);
                        HOperatorSet.Difference(ho_DifferenceRegionL, ho_RegionClosingR, out HObject ho_DifferenceRegionR);
                        HOperatorSet.ReduceDomain(ho_Image, ho_DifferenceRegionR, out ho_imageReducd);

                    }
                    else
                    {
                        HOperatorSet.ReduceDomain(ho_Image, ho_DifferenceRegion, out ho_imageReducd);
                    }
                    Threshold.Dispose();
                    HOperatorSet.Threshold(ho_imageReducd, out Threshold, JEGrayMin, JEGrayMax);
                    HOperatorSet.ErosionRectangle1(Threshold, out ho_ErosionRegion, 5, 5);

                    HOperatorSet.AreaCenter(ho_ErosionRegion, out HTuple area, out _, out _);
                    double areaPhy = area * PixelRatio * PixelRatio;//余料面积
                    if (areaPhy > JeOddmentsArea)
                    {
                        hv_WindowHandle.SetColor("red");
                        hv_WindowHandle.DispObj(ho_ErosionRegion);
                        HOperatorSet.NewLine(hv_WindowHandle);
                        hv_WindowHandle.WriteString($"极耳余料NG：{areaPhy:F2}");
                        hv_Result = "极耳余料";
                    }
                }


                ho_Rectangle.Dispose(); ho_RectangleLArc.Dispose(); ho_RectangleRArc.Dispose();
                ho_ImageReduced.Dispose(); ho_ImageReducedLArc.Dispose(); ho_ImageReducedRArc.Dispose();
                ho_Regions.Dispose(); ho_RegionsLArc.Dispose(); ho_RegionsRArc.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ErosionRectangle.Dispose();
                ho_Threshold.Dispose();
                ErosionRegion.Dispose(); ho_DifferenceRegion.Dispose(); ho_imageReducd.Dispose(); Threshold.Dispose();
            }
            catch (Exception)
            {
                hv_Result = "极耳打折";//结果赋值NG
                hv_WindowHandle.SetColor("red");
                HOperatorSet.NewLine(hv_WindowHandle);
                hv_WindowHandle.WriteString($"极耳检测异常，检查参数是否正确");
                //ho_Rectangle.Dispose();
                //ho_ImageReduced.Dispose();
                //ho_Regions.Dispose();
                //ho_ConnectedRegions.Dispose();
                //ho_SelectedRegions.Dispose();
                //ho_ErosionRectangle.Dispose();
                //ho_Threshold.Dispose();
            }
        }

        /// <summary>
        /// 极耳打折检测_极耳双相机
        /// </summary>
        /// <param name="ho_Image"></param>
        /// <param name="hv_WindowHandle"></param>
        /// <param name="param"></param>
        /// <param name="hv_Result"></param>
        public static void JeDetectP_Two(HObject ho_Image, HWindow hv_WindowHandle, string JELocation, double[] param, HTuple JeRow, HTuple JeCol, out string hv_Result, HTuple Row = null, HTuple Col = null, int flag = 0)
        {
            #region 配置参数
            //检测框Row
            double row = param[0];
            //检测框COl
            double col = param[1];
            //像素比
            double PixelRatio = param[2];
            //最小灰度值
            double JEGrayMin = param[3];
            //最大灰度值
            double JEGrayMax = param[4];
            //标准面积
            double JEAreaStandard = param[5];
            //面积容差
            double JEAreaRange = param[6];
            //余料面积
            double JeOddmentsArea = param[7];
            //X内缩
            double JEColumnErosion = param[8];
            //Y内缩
            double JERowErosion = param[9];
            //矩形度
            double JERectangularity = param[10];
            //缺口最小灰度值
            int JEGapGrayMin = (int)param[11];
            //缺口最大灰度值
            int JEGapGrayMax = (int)param[12];
            //缺口面积上限
            double JEGapAreaMax = param[13];
            //检测框高
            double JEHeight = param[14];
            //检测框宽
            double JEWidth = param[15];
            //上圆弧缺口面积上限
            double ArcArea = param[16];
            //下圆弧面积上限
            double ArcArea_R = param[17];

            //下圆弧面积下限
            double ArcAreamin_R = param[19];

            HTuple hv_Area = null;
            HObject ho_Rectangle, ho_ImageReduced, ho_RectangleLArc, ho_RectangleRArc, ho_ImageReducedLArc, ho_ImageReducedRArc;
            HObject ho_Regions, ho_ConnectedRegions, ho_SelectedRegions, ho_RegionsLArc, ho_RegionsRArc;
            HOperatorSet.GenEmptyObj(out ho_Rectangle); HOperatorSet.GenEmptyObj(out ho_RectangleLArc); HOperatorSet.GenEmptyObj(out ho_RectangleRArc);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_ImageReducedLArc);
            HOperatorSet.GenEmptyObj(out ho_ImageReducedRArc);
            HOperatorSet.GenEmptyObj(out ho_Regions); HOperatorSet.GenEmptyObj(out ho_RegionsLArc); HOperatorSet.GenEmptyObj(out ho_RegionsRArc);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out HObject ho_ErosionRectangle);
            HOperatorSet.GenEmptyObj(out HObject ho_Threshold);

            #endregion

            try
            {
                hv_Result = "ok";
                HOperatorSet.GenRectangle2(out ho_Rectangle, row, col, 0, JEWidth / PixelRatio / 2, JEHeight / PixelRatio / 2);
                hv_WindowHandle.SetColor("blue");
                hv_WindowHandle.DispObj(ho_Rectangle);
                HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced);
                HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, JEGrayMin, JEGrayMax);
                // 内缩为0就不进行内缩
                if (JEColumnErosion != 0 && JERowErosion != 0)
                {
                    HOperatorSet.ErosionRectangle1(ho_Regions, out ho_ErosionRectangle, JEColumnErosion / PixelRatio, JERowErosion / PixelRatio);
                    //HOperatorSet.DilationRectangle1(ho_ErosionRectangle, out HObject ho_ErosionRectangle1, JEColumnErosion / PixelRatio, JERowErosion / PixelRatio);
                    HOperatorSet.Connection(ho_ErosionRectangle, out ho_ConnectedRegions);
                }
                else
                {
                    HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
                }
                HOperatorSet.SelectShape(ho_ConnectedRegions, out HObject ho_SelectedRegion, "area", "and", 500, 999999999999);//剔除一些干扰点 
                HOperatorSet.Union1(ho_SelectedRegion, out ho_SelectedRegions);
                HOperatorSet.AreaCenter(ho_SelectedRegions, out hv_Area, out _, out _);
                HOperatorSet.TupleLength(hv_Area, out HTuple hv_Length);


                //是否存在极耳判断
                if (!(hv_Length >= 1))
                {
                    hv_Result = "极耳打折";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    //  hv_WindowHandle.SetTposition(height.I - 300, 1);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString(" 未检测到极耳");
                    return;
                }
                double d_Area = (hv_Area * PixelRatio * PixelRatio); //计算极耳面积
                //面积是否超限判断                                                   
                if ((d_Area < JEAreaStandard - JEAreaRange) /*|| (d_Area > JEAreaStandard + JEAreaRange)*/)
                {
                    hv_Result = "极耳打折";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    hv_WindowHandle.DispObj(ho_SelectedRegions);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString($"极耳打折NG：{d_Area:F2}");
                    //return;
                }

                if (d_Area > JEAreaStandard + JEAreaRange)
                {
                    hv_Result = "极耳余料";//结果赋值NG
                    hv_WindowHandle.SetColor("red");
                    hv_WindowHandle.DispObj(ho_SelectedRegions);
                    HOperatorSet.NewLine(hv_WindowHandle);
                    hv_WindowHandle.WriteString($"极耳余料NG：{d_Area:F2}");
                    //return;
                }


                //矩形度设定值不等于0，进行矩形度检测
                if (JERectangularity != 0)
                {
                    HOperatorSet.Rectangularity(ho_SelectedRegions, out HTuple hv_rectangularity);
                    //矩形度是否超限判断
                    if (hv_rectangularity < JERectangularity)
                    {
                        hv_Result = "极耳打折";//结果赋值NG
                        hv_WindowHandle.SetColor("red");
                        hv_WindowHandle.DispObj(ho_SelectedRegions);
                        // hv_WindowHandle.SetTposition(height.I - 300, 1);
                        HOperatorSet.NewLine(hv_WindowHandle);
                        hv_WindowHandle.WriteString($"极耳矩形相似度NG:{hv_rectangularity.D:F2}"); /*return;*/
                    }
                }

                HOperatorSet.GenEmptyObj(out HObject ho_Region);
                HOperatorSet.GenEmptyObj(out HObject ErosionRegion);
                HOperatorSet.GenEmptyObj(out HObject imageReducd);
                HOperatorSet.GenEmptyObj(out HObject ho_Region1);
                HObject ho_RegionClosing = new HObject();
                if (JEGapAreaMax != 0 /*&& param[21] != 0*/)//缺口面积不等于0，进行缺口检测
                {
                    HTuple intersectionRow1 = new HTuple(), intersectionCol1 = new HTuple(), intersectionRow2 = new HTuple(), intersectionCol2 = new HTuple(), intersectionRow3 = new HTuple(), intersectionCol3 = new HTuple(), intersectionRow4 = new HTuple(), intersectionCol4 = new HTuple();
                    HObject circle = new HObject(), regionDifference = new HObject();
                    HObject hObject = new HObject();
                    switch (JELocation)
                    {
                        case "左上": break;
                        case "右上": break;
                        case "左下":
                            //极耳检测框上边与极耳检测框右边交点
                            HOperatorSet.IntersectionLl(row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), row + (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), out intersectionRow1, out intersectionCol1, out _);
                            if (flag == 1)
                            {
                                //极耳右竖边与极耳横边1交点
                                HOperatorSet.IntersectionLl(row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), row + (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), JeRow[10], JeCol[10], JeRow[11], JeCol[11], out intersectionRow2, out intersectionCol2, out _);
                                //极耳横边1与极耳左竖边交点
                                HOperatorSet.IntersectionLl(JeRow[10], JeCol[10], JeRow[11], JeCol[11], JeRow[4], JeCol[4], JeRow[5], JeCol[5], out intersectionRow3, out intersectionCol3, out _);
                            }
                            else
                            {
                                //极耳右竖边与极耳横边交点
                                HOperatorSet.IntersectionLl(row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), row + (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), JeRow[2], JeCol[2], JeRow[3], JeCol[3], out intersectionRow2, out intersectionCol2, out _);
                                //极耳横边与极耳左竖边交点
                                HOperatorSet.IntersectionLl(JeRow[2], JeCol[2], JeRow[3], JeCol[3], JeRow[4], JeCol[4], JeRow[5], JeCol[5], out intersectionRow3, out intersectionCol3, out _);
                            }

                            //极耳左竖边与极耳检测框上边交点
                            HOperatorSet.IntersectionLl(JeRow[4], JeCol[4], JeRow[5], JeCol[5], row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), out intersectionRow4, out intersectionCol4, out _);
                            HOperatorSet.GenCircle(out circle, intersectionRow2, intersectionCol2, 3 / PixelRatio);
                            break;
                        case "右下":
                            //极耳检测框上边与极耳右竖边交点
                            HOperatorSet.IntersectionLl(row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), JeRow[6], JeCol[6], JeRow[7], JeCol[7], out intersectionRow1, out intersectionCol1, out _);
                            if (flag == 1)
                            {
                                //极耳右竖边与极耳横边交点
                                HOperatorSet.IntersectionLl(JeRow[6], JeCol[6], JeRow[7], JeCol[7], JeRow[10], JeCol[10], JeRow[11], JeCol[11], out intersectionRow2, out intersectionCol2, out _);
                                //极耳横边与极耳检测框左边交点
                                HOperatorSet.IntersectionLl(JeRow[10], JeCol[10], JeRow[11], JeCol[11], row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row + (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), out intersectionRow3, out intersectionCol3, out _);
                            }
                            else
                            {
                                //极耳右竖边与极耳横边交点
                                HOperatorSet.IntersectionLl(JeRow[6], JeCol[6], JeRow[7], JeCol[7], JeRow[2], JeCol[2], JeRow[3], JeCol[3], out intersectionRow2, out intersectionCol2, out _);
                                //极耳横边与极耳检测框左边交点
                                HOperatorSet.IntersectionLl(JeRow[2], JeCol[2], JeRow[3], JeCol[3], row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row + (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), out intersectionRow3, out intersectionCol3, out _);
                            }

                            //极耳检测框左边与极耳检测框上边交点
                            HOperatorSet.IntersectionLl(row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row + (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col - (JEWidth / PixelRatio / 2), row - (JEHeight / PixelRatio / 2), col + (JEWidth / PixelRatio / 2), out intersectionRow4, out intersectionCol4, out _);
                            HOperatorSet.GenCircle(out circle, intersectionRow3, intersectionCol3, 3 / PixelRatio);

                            break;
                        default: break;
                    }

                    double[] Gaprow = new double[] { intersectionRow1, intersectionRow2, intersectionRow3, intersectionRow4 }, Gapcol = new double[] { intersectionCol1, intersectionCol2, intersectionCol3, intersectionCol4 };
                    ho_Region.Dispose();
                    HOperatorSet.GenRegionPolygonFilled(out ho_Region, Gaprow, Gapcol);


                    if (ArcArea_R != 0)
                    {
                        HOperatorSet.Difference(ho_Region, circle, out regionDifference);
                        HOperatorSet.ErosionRectangle1(regionDifference, out ErosionRegion, 9, 9);
                    }
                    else
                    {
                        ErosionRegion.Dispose();
                        HOperatorSet.ErosionRectangle1(ho_Region, out ErosionRegion, 9, 9);
                    }
                    imageReducd.Dispose();
                    HOperatorSet.ReduceDomain(ho_Image, ErosionRegion, out imageReducd);
                    ho_Region1.Dispose();
                    HOperatorSet.Threshold(imageReducd, out ho_Region1, JEGapGrayMin, JEGapGrayMax);
                    HOperatorSet.Connection(ho_Region1, out HObject connectedRegions);
                    HOperatorSet.SelectShape(connectedRegions, out HObject ho_SelectedRegion1, "area", "and", 30, 999999999999);//剔除一些干扰点 
                    HOperatorSet.DilationRectangle1(ho_SelectedRegion1, out HObject regionDilation, 1, 1);
                    HOperatorSet.AreaCenter(regionDilation, out HTuple area, out _, out _);
                    if (area.Length > 0)
                    {
                        double areaPhy = area * PixelRatio * PixelRatio;//缺口面积
                        if (areaPhy > JEGapAreaMax)//缺口面积是否超限判断
                        {
                            hv_WindowHandle.SetColor("red");
                            hv_WindowHandle.DispObj(regionDilation);
                            HOperatorSet.NewLine(hv_WindowHandle);
                            hv_WindowHandle.WriteString($"极耳缺口NG：{areaPhy:F2}-极耳打折");
                            hv_Result = "极耳打折";
                            //return;
                        }
                    }
                    if (ArcArea_R != 0)
                    {
                        HOperatorSet.ReduceDomain(ho_Image, circle, out HObject imageReducedL);
                        HOperatorSet.Threshold(imageReducedL, out HObject regionL, 200, 255);
                        HOperatorSet.AreaCenter(regionL, out HTuple area1L, out _, out _);
                        double L = area1L * PixelRatio * PixelRatio;
                        if (L > ArcArea_R || L < ArcAreamin_R)
                        {
                            hv_WindowHandle.SetColor("red");
                            hv_WindowHandle.DispObj(regionL);
                            HOperatorSet.NewLine(hv_WindowHandle);
                            hv_WindowHandle.WriteString($"极耳下圆弧NG：{L:F2}-极耳打折");
                            hv_Result = "极耳打折";
                        }


                    }


                    if (ArcArea != 0)
                    {
                        HTuple hv_Row_JD = new HTuple(), hv_Column_JD = new HTuple();
                        switch (JELocation)
                        {
                            case "左上": break;
                            case "右上": break;
                            case "左下":  //极片左横边与极耳左竖边交点
                                HOperatorSet.IntersectionLl(Row[0], Col[0], Row[1], Col[1], JeRow[4], JeCol[4], JeRow[5], JeCol[5], out hv_Row_JD, out hv_Column_JD, out _);
                                break;
                            case "右下": //极片右横边与极耳右竖边交点
                                HOperatorSet.IntersectionLl(Row[0], Col[0], Row[1], Col[1], JeRow[6], JeCol[6], JeRow[7], JeCol[7], out hv_Row_JD, out hv_Column_JD, out _);
                                break;
                            default: break;
                        }

                        //生成圆区域，检测黑色区域，膨胀，腐蚀，连接破损断裂处弧-----0711--------------*
                        HOperatorSet.GenCircle(out HObject ho_Circle0, hv_Row_JD, hv_Column_JD, 260);
                        HOperatorSet.ReduceDomain(ho_Image, ho_Circle0, out HObject ho_ImageReduced0L
                            );
                        HOperatorSet.BinaryThreshold(ho_ImageReduced0L, out HObject ho_Region0L, "max_separability",
                            "dark", out _);
                        HOperatorSet.OpeningCircle(ho_Region0L, out HObject ho_Region1L, 50);
                        HOperatorSet.ClosingCircle(ho_Region1L, out ho_RegionClosing, 110);
                        //HOperatorSet.GenContourRegionXld(ho_RegionClosingL, out  ho_ContoursL, "border");
                        hv_WindowHandle.SetColor("blue");
                        HOperatorSet.ErosionRectangle1(ho_RegionClosing, out ho_RegionClosing, 6, 6);
                        HOperatorSet.DispObj(ho_RegionClosing, hv_WindowHandle);
                        //破损面积*
                        hv_Area.Dispose();
                        hv_Area = 0;
                        HOperatorSet.ReduceDomain(ho_Image, ho_RegionClosing, out HObject ho_ImageReducedL
                            );
                        HOperatorSet.Threshold(ho_ImageReducedL, out HObject ho_RegionL, param[20],
                            255);
                        HOperatorSet.Connection(ho_RegionL, out HObject ho_ConnectedRegionsL);
                        HOperatorSet.SelectShape(ho_ConnectedRegionsL, out HObject ho_SelectedRegionsL, "area",
                            "and", 3, 9999999);
                        hv_Area.Dispose();
                        HOperatorSet.AreaCenter(ho_SelectedRegionsL, out hv_Area, out _, out _);
                        {
                            HTuple ExpTmpOutVar_0;
                            HOperatorSet.TupleSum(hv_Area, out ExpTmpOutVar_0);
                            hv_Area.Dispose();
                            hv_Area = ExpTmpOutVar_0;
                        }
                        if (hv_Area > 0)
                        {
                            double hv_AreaL = hv_Area * PixelRatio * PixelRatio;
                            if (hv_AreaL > ArcArea)
                            {
                                hv_WindowHandle.SetColor("red");
                                hv_WindowHandle.DispObj(ho_SelectedRegionsL);
                                HOperatorSet.NewLine(hv_WindowHandle);
                                hv_WindowHandle.WriteString($"极耳上圆弧NG：{hv_AreaL:F4}-极耳打折");
                                hv_Result = "极耳打折";
                            }
                        }


                        ////极片右横边与极耳右竖边交点
                        //HOperatorSet.IntersectionLl(Row[9], Col[9], Row[10], Col[10], JeRow[6], JeCol[6], JeRow[7], JeCol[7], out hv_Row_JD, out hv_Column_JD, out _);
                        ////生成圆区域，检测黑色区域，膨胀，腐蚀，连接破损断裂处弧-----0711--------------*
                        //HOperatorSet.GenCircle(out ho_Circle0, hv_Row_JD, hv_Column_JD, 260);
                        //HOperatorSet.ReduceDomain(ho_Image, ho_Circle0, out ho_ImageReduced0L
                        //    );

                        //HOperatorSet.BinaryThreshold(ho_ImageReduced0L, out ho_Region0L, "max_separability",
                        //    "dark", out _);
                        //HOperatorSet.OpeningCircle(ho_Region0L, out ho_Region1L, 50);
                        //HOperatorSet.ClosingCircle(ho_Region1L, out ho_RegionClosingR, 110);
                        ////HOperatorSet.GenContourRegionXld(ho_RegionClosingL, out ho_ContoursR, "border");
                        //hv_WindowHandle.SetColor("blue");
                        //HOperatorSet.DispObj(ho_RegionClosingR, hv_WindowHandle);
                        ////破损面积*
                        //hv_Area.Dispose();
                        //hv_Area = 0;
                        //ho_ImageReducedL.Dispose();
                        //HOperatorSet.ErosionRectangle1(ho_RegionClosingR, out ho_RegionClosingR, 6, 6);
                        //HOperatorSet.ReduceDomain(ho_Image, ho_RegionClosingR, out ho_ImageReducedL
                        //    );

                        //HOperatorSet.Threshold(ho_ImageReducedL, out ho_RegionL, param[20],
                        //    255);
                        //HOperatorSet.Connection(ho_RegionL, out ho_ConnectedRegionsL);
                        //HOperatorSet.SelectShape(ho_ConnectedRegionsL, out ho_SelectedRegionsL, "area",
                        //    "and", 3, 99999);
                        //hv_Area.Dispose();
                        //HOperatorSet.AreaCenter(ho_SelectedRegionsL, out hv_Area, out _, out _);
                        //{
                        //    HTuple ExpTmpOutVar_0;
                        //    HOperatorSet.TupleSum(hv_Area, out ExpTmpOutVar_0);
                        //    hv_Area.Dispose();
                        //    hv_Area = ExpTmpOutVar_0;
                        //}
                        //if (hv_Area > 0)
                        //{
                        //    double hv_AreaL = hv_Area * PixelRatio * PixelRatio;
                        //    if (hv_AreaL > ArcArea)
                        //    {
                        //        hv_WindowHandle.SetColor("red");
                        //        hv_WindowHandle.DispObj(ho_SelectedRegionsL);
                        //        HOperatorSet.NewLine(hv_WindowHandle);
                        //        hv_WindowHandle.WriteString($"极耳右上圆弧NG：{hv_AreaL:F4}-极耳打折");
                        //        hv_Result = "极耳打折";
                        //    }
                        //}

                    }
                }

                HOperatorSet.GenEmptyObj(out HObject ho_DifferenceRegion);
                HOperatorSet.GenEmptyObj(out HObject ho_ErosionRegion);
                HOperatorSet.GenEmptyObj(out HObject ho_imageReducd);
                HOperatorSet.GenEmptyObj(out HObject Threshold);
                if (JeOddmentsArea != 0 /*&& param[21] != 0*/)
                {
                    ho_DifferenceRegion.Dispose();
                    HOperatorSet.Difference(ho_Rectangle, ho_Region, out ho_DifferenceRegion);
                    HOperatorSet.ErosionRectangle1(ho_DifferenceRegion, out ho_DifferenceRegion, 0.5 / PixelRatio, 0.5 / PixelRatio);


                    if (ArcArea != 0)
                    {
                        HOperatorSet.Difference(ho_DifferenceRegion, ho_RegionClosing, out HObject ho_Difference);

                        HOperatorSet.ReduceDomain(ho_Image, ho_Difference, out ho_imageReducd);

                    }
                    else
                    {
                        HOperatorSet.ReduceDomain(ho_Image, ho_DifferenceRegion, out ho_imageReducd);
                    }
                    Threshold.Dispose();
                    HOperatorSet.Threshold(ho_imageReducd, out Threshold, JEGrayMin, JEGrayMax);
                    HOperatorSet.ErosionRectangle1(Threshold, out ho_ErosionRegion, 5, 5);

                    HOperatorSet.AreaCenter(ho_ErosionRegion, out HTuple area, out _, out _);
                    double areaPhy = area * PixelRatio * PixelRatio;//余料面积
                    if (areaPhy > JeOddmentsArea)
                    {
                        hv_WindowHandle.SetColor("red");
                        hv_WindowHandle.DispObj(ho_ErosionRegion);
                        HOperatorSet.NewLine(hv_WindowHandle);
                        hv_WindowHandle.WriteString($"极耳余料NG：{areaPhy:F2}");
                        hv_Result = "极耳余料";
                    }
                }


                ho_Rectangle.Dispose(); ho_RectangleLArc.Dispose(); ho_RectangleRArc.Dispose();
                ho_ImageReduced.Dispose(); ho_ImageReducedLArc.Dispose(); ho_ImageReducedRArc.Dispose();
                ho_Regions.Dispose(); ho_RegionsLArc.Dispose(); ho_RegionsRArc.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions.Dispose();
                ho_ErosionRectangle.Dispose();
                ho_Threshold.Dispose();
                ErosionRegion.Dispose(); ho_DifferenceRegion.Dispose(); ho_imageReducd.Dispose(); Threshold.Dispose();
            }
            catch (Exception)
            {
                hv_Result = "极耳打折";//结果赋值NG
                hv_WindowHandle.SetColor("red");
                HOperatorSet.NewLine(hv_WindowHandle);
                hv_WindowHandle.WriteString($"极耳检测异常，检查参数是否正确");
                //ho_Rectangle.Dispose();
                //ho_ImageReduced.Dispose();
                //ho_Regions.Dispose();
                //ho_ConnectedRegions.Dispose();
                //ho_SelectedRegions.Dispose();
                //ho_ErosionRectangle.Dispose();
                //ho_Threshold.Dispose();
            }
        }
        /// <summary>
        /// 缺角检测-矩形框
        /// </summary>
        /// <param name="image"></param>
        /// <param name="hw"></param>
        /// <param name="triangle">三角形检测框</param>
        /// <param name="param">参数</param>
        /// <param name="BevelArea">面积</param>
        public static void BevelDetectP(HObject image, HWindow hw, bool triangle, double[] param, out double BevelArea)
        {
            //极片角点坐标
            double row = param[0];
            double col = param[1];
            //缺角最小灰度值
            double BevelGrayMin = param[2];
            //缺角框大小
            double BevelFrame = param[3];
            //像素比
            double PixelRatio = param[4];
            //补偿值
            double Compensate = param[5];
            //偏移
            double RowSkew = param[6];
            double ColSkew = param[7];
            //横边
            double rowBegin1 = param[8];
            double colBegin1 = param[9];
            double rowEnd1 = param[10];
            double colEnd1 = param[11];
            //竖边
            double rowBegin2 = param[12];
            double colBegin2 = param[13];
            double rowEnd2 = param[14];
            double colEnd2 = param[15];

            HOperatorSet.GenEmptyObj(out HObject ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out HObject ho_iamgeReduced);
            HOperatorSet.GenEmptyObj(out HObject ho_region);
            HOperatorSet.GenEmptyObj(out HObject ho_regionErosion);

            if (!triangle)
            {
                ho_Rectangle2.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle2, row + RowSkew / PixelRatio, col + ColSkew / PixelRatio, 0, BevelFrame / PixelRatio / 2, BevelFrame / PixelRatio / 2);
                hw.SetColor("blue");
                hw.DispRectangle2(row + RowSkew / PixelRatio, col + ColSkew / PixelRatio, 0, BevelFrame / PixelRatio / 2, BevelFrame / PixelRatio / 2);
            }
            else
            {
                //横边角度
                double LateralEdgeAngle = Math.Atan2(rowEnd1 - rowBegin1, colEnd1 - colBegin1);
                double Row = Math.Abs(Math.Sin(LateralEdgeAngle) * BevelFrame / PixelRatio);
                double Col = Math.Abs(Math.Cos(LateralEdgeAngle) * BevelFrame / PixelRatio);
                double LateralEdgeRow = row - Row;
                double LateralEdgeCol = col - Col;
                if (row < rowBegin1)
                {
                    LateralEdgeRow = row + Row;
                }
                if (col < colBegin1)
                {
                    LateralEdgeCol = col + Col;
                }
                //竖边角度
                double VerticalEdgeAngle = Math.Atan2(rowEnd2 - rowBegin2, colEnd2 - colBegin2);
                Row = Math.Abs(Math.Sin(VerticalEdgeAngle) * BevelFrame / PixelRatio);
                Col = Math.Abs(Math.Cos(VerticalEdgeAngle) * BevelFrame / PixelRatio);
                double VerticalRow = row - Row;
                double VerticalCol = col - Col;
                if (row < rowBegin2)
                {
                    VerticalRow = row + Row;
                }
                if (col < colBegin2)
                {
                    VerticalCol = col + Col;
                }

                double[] rows = { row, LateralEdgeRow, VerticalRow }; double[] columns = { col, LateralEdgeCol, VerticalCol };
                //图像处理
                ho_Rectangle2.Dispose();
                HOperatorSet.GenRegionPolygonFilled(out ho_Rectangle2, rows, columns);
                hw.SetColor("blue");
                hw.DispObj(ho_Rectangle2);

            }
            ho_iamgeReduced.Dispose();
            HOperatorSet.ReduceDomain(image, ho_Rectangle2, out ho_iamgeReduced);
            ho_region.Dispose();
            HOperatorSet.Threshold(ho_iamgeReduced, out ho_region, BevelGrayMin, 255);
            ho_regionErosion.Dispose();
            HOperatorSet.ErosionRectangle1(ho_region, out ho_regionErosion, 2, 2);
            HOperatorSet.AreaCenter(ho_regionErosion, out HTuple hv_area, out _, out _);
            BevelArea = Math.Round((hv_area * PixelRatio * PixelRatio).D + Compensate, 3);

            ho_Rectangle2.Dispose();
            ho_iamgeReduced.Dispose();
            ho_region.Dispose();
            ho_regionErosion.Dispose();
        }
        /// <summary>
        /// 是否空片检测
        /// </summary>
        /// <param name="ho_Image"></param>
        /// <param name="measureLine"></param>
        /// <param name="hv_Result"></param>
        public static void NullSliceDetect(HObject ho_Image, HWindow hw, MeasureLine measureLine, double NullSliceMax, double pix, out bool hv_Result)
        {
            hv_Result = true;
            try
            {
                HOperatorSet.GenRectangle2(out HObject regoin, measureLine.行坐标, measureLine.列坐标, 0, measureLine.半宽, 2.5 / pix);
                HOperatorSet.ReduceDomain(ho_Image, regoin, out HObject imagereduced);
                HOperatorSet.Threshold(imagereduced, out HObject thresholdregion, 1, 100);
                HOperatorSet.AreaCenter(thresholdregion, out HTuple area, out _, out _);
                hv_Result = true;
                hw.SetColor("blue");
                hw.DispObj(regoin);
                if (area > 0)
                {
                    double darea = area * pix * pix;
                    if (darea < 50)
                    {
                        hw.SetColor("red");
                        hw.DispObj(thresholdregion);
                        hv_Result = false;
                        HOperatorSet.NewLine(hw);
                        hw.WriteString($"空片NG：{darea}");
                    }

                }
                else
                {
                    hw.SetColor("red");
                    hw.DispObj(thresholdregion);
                    hv_Result = false;
                    HOperatorSet.NewLine(hw);
                    hw.WriteString($"空片NG：{0}");
                }
            }
            catch (Exception)
            {

            }


        }


        /// <summary>
        /// 显示找边框
        /// </summary>
        /// <param name="hw"></param>
        /// <param name="measureLine"></param>
        public static void DispRectangle2(HWindow hw, MeasureLine measureLine)
        {
            hw.DispRectangle2(measureLine.行坐标, measureLine.列坐标, measureLine.弧度, measureLine.半宽, measureLine.半高);
            hw.DispArrow(measureLine.行坐标 - Math.Sin(measureLine.弧度) * (measureLine.半宽 - 20), measureLine.列坐标 + Math.Cos(measureLine.弧度) * (measureLine.半宽 - 20), measureLine.行坐标 - Math.Sin(measureLine.弧度) * (measureLine.半宽 + 40), measureLine.列坐标 + Math.Cos(measureLine.弧度) * (measureLine.半宽 + 40), 2);

        }




        //magical 要启用增加最强边的计算 找最明显边 设transition值== "strongest"，此方法里并没有开放这个参数，可以自己开放  wcf20230726   
        //public static bool MeasureLine(HObject Image, HWindow_F hWindow_F, MeasureLine measureLine, out HTuple hv_StartRow, out HTuple hv_StartColumn, out HTuple hv_EndRow, out HTuple hv_EndColumn)
        //{
        //    try
        //    {

        //        HObject ho_RegionLines3;
        //        HOperatorSet.GenEmptyObj(out ho_RegionLines3);
        //        HTuple hv_HomMat2DIdentity1, hv_HomMat2DRotate1, hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1;
        //        //测量矩形中线2 平行于边缘
        //        HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity1);
        //        HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity1, measureLine.弧度 - ((new HTuple(90)).TupleRad()
        //            ), measureLine.行坐标, measureLine.列坐标, out hv_HomMat2DRotate1);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, measureLine.行坐标, measureLine.列坐标 + measureLine.半高,
        //            out hv_RowTrans, out hv_ColTrans);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, measureLine.行坐标, measureLine.列坐标 - measureLine.半高,
        //            out hv_RowTrans1, out hv_ColTrans1);
        //        //ho_RegionLines3.Dispose();
        //        //HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //        //    hv_ColTrans1);    
        //        //HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //        //    hv_ColTrans1);
        //        //hWindow_F.DispObj(ho_RegionLines3);
        //        HOperatorSet.GenRectangle2(out HObject rectangle, measureLine.行坐标, measureLine.列坐标, measureLine.弧度, measureLine.半宽, measureLine.半高);
        //        hWindow_F.DispObj(rectangle, "green");

        //        #region 给参数赋值
        //        Line_INFO line_INFO = new Line_INFO(hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1);
        //        Metrology_INFO m_MetrologyInfo = new Metrology_INFO();
        //        m_MetrologyInfo.Length1 = measureLine.半宽;
        //        m_MetrologyInfo.Length2 = measureLine.半高 / 20;
        //        m_MetrologyInfo.Threshold = measureLine.阈值;
        //        m_MetrologyInfo.MeasureDis = measureLine.步长;
        //        m_MetrologyInfo.PointsOrder = 0;//cb_Direction.SelectedIndex;
        //        m_MetrologyInfo.Sigma = measureLine.滤波系数;
        //        string transition, select;
        //        switch (measureLine.过渡方式)
        //        {
        //            case Transition.白到黑: transition = "negative"; break;
        //            case Transition.黑到白: transition = "positive"; break;
        //            default: transition = "all"; break;
        //        }
        //        switch (measureLine.选择点)
        //        {
        //            case Select.第一个点: select = "first"; break;
        //            case Select.最后一个点: select = "last"; break;
        //            default: select = "all"; break;
        //        }
        //        //string mTransition = "negative";
        //        //string m_PointsOrder = "positive"; //传输点的方向是顺时针还是逆时针暂时还没有设计
        //        //string mSelect = "first";
        //        //mSelect = "strongest";//magical  增加最强边边缘
        //        //Measure_select = "strongest";//magical  增加最强边边缘
        //        m_MetrologyInfo.ParamName = new HTuple();
        //        m_MetrologyInfo.ParamName.Append("measure_transition");
        //        m_MetrologyInfo.ParamName.Append("measure_select");
        //        m_MetrologyInfo.ParamName.Append("measure_distance");
        //        //m_MetrologyInfo.ParamName.Append("max_num_iterations");
        //        //m_MetrologyInfo.ParamName.Append("measure_interpolation");
        //        m_MetrologyInfo.ParamValue = new HTuple();
        //        m_MetrologyInfo.ParamValue.Append(transition);
        //        m_MetrologyInfo.ParamValue.Append(select);
        //        m_MetrologyInfo.ParamValue.Append(m_MetrologyInfo.MeasureDis);
        //        #endregion
        //        HImage hImage = new HImage();
        //        HobjectToHimage(Image, ref hImage);
        //        //HTuple outR, outC;  HXLDCont outMeasureXLD; HRegion disableRegion = null;
        //        HRegion disableRegion = null;

        //        bool result = MeasureLine(hImage, line_INFO, m_MetrologyInfo,
        //                     out Line_INFO outLine, out HTuple outR, out HTuple outC, out HXLDCont outMeasureXLD, disableRegion);
        //        HXLDCont m_MeasureCross = new HXLDCont();
        //        //HXLDCont m_ResultXLD = new HXLDCont();
        //        m_MeasureCross.GenCrossContourXld(outR, outC, (HTuple)m_MetrologyInfo.Length2, new HTuple(outLine.Nx + new HTuple(30).TupleRad()));
        //        //m_ResultXLD.GenContourPolygonXld(new HTuple(outLine.StartY, outLine.EndY), new HTuple(outLine.StartX, outLine.EndX));
        //        //hWindow_F.DispObj(m_ResultXLD, "red");
        //        hWindow_F.DispObj(m_MeasureCross, "blue");
        //        hv_StartRow = outLine.StartY; hv_StartColumn = outLine.StartX;
        //        hv_EndRow = outLine.EndY; hv_EndColumn = outLine.EndX;
        //        HOperatorSet.GenRegionLine(out HObject LineInfo, hv_StartRow, hv_StartColumn, hv_EndRow, hv_EndColumn);
        //        hWindow_F.DispObj(LineInfo, "red");
        //        if (!result)
        //        {
        //            hv_StartRow = 0; hv_StartColumn = 0;
        //            hv_EndRow = 0; hv_EndColumn = 0;
        //        }
        //        return result;
        //    }
        //    catch (Exception e)
        //    {

        //        Tool.LogForm(e);
        //        hv_StartRow = 0; hv_StartColumn = 0;
        //        hv_EndRow = 0; hv_EndColumn = 0;
        //        return false;
        //    }
        //}

        /// <summary>
        /// 跟随找边
        /// </summary>
        /// <param name="Image"></param>
        /// <param name="hWindow_F"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <param name="measureLine"></param>
        /// <param name="hv_StartRow"></param>
        /// <param name="hv_StartColumn"></param>
        /// <param name="hv_EndRow"></param>
        /// <param name="hv_EndColumn"></param>
        /// <returns></returns>
        //public static bool MeasureLine(HObject Image, HWindow_F hWindow_F, double row, double col, MeasureLine measureLine, out HTuple hv_StartRow, out HTuple hv_StartColumn, out HTuple hv_EndRow, out HTuple hv_EndColumn)
        //{
        //    try
        //    {

        //        HObject ho_RegionLines3;
        //        HOperatorSet.GenEmptyObj(out ho_RegionLines3);
        //        HTuple hv_HomMat2DIdentity1, hv_HomMat2DRotate1, hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1;
        //        测量矩形中线2 平行于边缘
        //        HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity1);
        //        HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity1, measureLine.弧度 - ((new HTuple(90)).TupleRad()
        //            ), row, col, out hv_HomMat2DRotate1);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, row, col + measureLine.半高,
        //            out hv_RowTrans, out hv_ColTrans);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, row, col - measureLine.半高,
        //            out hv_RowTrans1, out hv_ColTrans1);
        //        ho_RegionLines3.Dispose();
        //        HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //            hv_ColTrans1);
        //        HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //            hv_ColTrans1);
        //        hWindow_F.DispObj(ho_RegionLines3);
        //        HOperatorSet.GenRectangle2(out HObject rectangle, row, col, measureLine.弧度, measureLine.半宽, measureLine.半高);
        //        hWindow_F.DispObj(rectangle, "green");

        //        #region 给参数赋值
        //        Line_INFO line_INFO = new Line_INFO(hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1);
        //        Metrology_INFO m_MetrologyInfo = new Metrology_INFO();
        //        m_MetrologyInfo.Length1 = measureLine.半宽;
        //        m_MetrologyInfo.Length2 = measureLine.半高 / 20;
        //        m_MetrologyInfo.Threshold = measureLine.阈值;
        //        m_MetrologyInfo.MeasureDis = measureLine.步长;
        //        m_MetrologyInfo.PointsOrder = 0;//cb_Direction.SelectedIndex;
        //        m_MetrologyInfo.Sigma = measureLine.滤波系数;
        //        string transition, select;
        //        switch (measureLine.过渡方式)
        //        {
        //            case Transition.白到黑: transition = "negative"; break;
        //            case Transition.黑到白: transition = "positive"; break;
        //            default: transition = "all"; break;
        //        }
        //        switch (measureLine.选择点)
        //        {
        //            case Select.第一个点: select = "first"; break;
        //            case Select.最后一个点: select = "last"; break;
        //            default: select = "all"; break;
        //        }
        //        string mTransition = "negative";
        //        string m_PointsOrder = "positive"; //传输点的方向是顺时针还是逆时针暂时还没有设计
        //        string mSelect = "first";
        //        mSelect = "strongest";//magical  增加最强边边缘
        //        Measure_select = "strongest";//magical  增加最强边边缘
        //        m_MetrologyInfo.ParamName = new HTuple();
        //        m_MetrologyInfo.ParamName.Append("measure_transition");
        //        m_MetrologyInfo.ParamName.Append("measure_select");
        //        m_MetrologyInfo.ParamName.Append("measure_distance");
        //        m_MetrologyInfo.ParamName.Append("max_num_iterations");
        //        m_MetrologyInfo.ParamName.Append("measure_interpolation");
        //        m_MetrologyInfo.ParamValue = new HTuple();
        //        m_MetrologyInfo.ParamValue.Append(transition);
        //        m_MetrologyInfo.ParamValue.Append(select);
        //        m_MetrologyInfo.ParamValue.Append(m_MetrologyInfo.MeasureDis);
        //        #endregion
        //        HImage hImage = new HImage();
        //        HobjectToHimage(Image, ref hImage);
        //        HTuple outR, outC; HXLDCont outMeasureXLD; HRegion disableRegion = null;
        //        HRegion disableRegion = null;

        //        bool result = MeasureLine(hImage, line_INFO, m_MetrologyInfo,
        //                     out Line_INFO outLine, out HTuple outR, out HTuple outC, out HXLDCont outMeasureXLD, disableRegion);
        //        HXLDCont m_MeasureCross = new HXLDCont();
        //        HXLDCont m_ResultXLD = new HXLDCont();
        //        m_MeasureCross.GenCrossContourXld(outR, outC, (HTuple)m_MetrologyInfo.Length2, new HTuple(outLine.Nx + new HTuple(30).TupleRad()));
        //        m_ResultXLD.GenContourPolygonXld(new HTuple(outLine.StartY, outLine.EndY), new HTuple(outLine.StartX, outLine.EndX));
        //        hWindow_F.DispObj(m_ResultXLD, "red");
        //        hWindow_F.DispObj(m_MeasureCross, "blue");
        //        hv_StartRow = outLine.StartY; hv_StartColumn = outLine.StartX;
        //        hv_EndRow = outLine.EndY; hv_EndColumn = outLine.EndX;
        //        HOperatorSet.GenRegionLine(out HObject LineInfo, hv_StartRow, hv_StartColumn, hv_EndRow, hv_EndColumn);
        //        hWindow_F.DispObj(LineInfo, "red");
        //        return result;
        //    }
        //    catch (Exception e)
        //    {
        //        Tool.LogForm(e);
        //        hv_StartRow = 0; hv_StartColumn = 0;
        //        hv_EndRow = 0; hv_EndColumn = 0;
        //        return false;
        //    }
        //}




        //public bool MeasureLineP(HObject Image, HWindow_F hWindow_F, MeasureLine measureLine, out HTuple hv_StartRow, out HTuple hv_StartColumn, out HTuple hv_EndRow, out HTuple hv_EndColumn)
        //{
        //    try
        //    {
        //        HObject ho_RegionLines3;
        //        HOperatorSet.GenEmptyObj(out ho_RegionLines3);
        //        HTuple hv_HomMat2DIdentity1, hv_HomMat2DRotate1, hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1;
        //        //测量矩形中线2 平行于边缘
        //        HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity1);
        //        HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity1, measureLine.弧度 - ((new HTuple(90)).TupleRad()
        //            ), measureLine.行坐标, measureLine.列坐标, out hv_HomMat2DRotate1);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, measureLine.行坐标, measureLine.列坐标 + measureLine.半高,
        //            out hv_RowTrans, out hv_ColTrans);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, measureLine.行坐标, measureLine.列坐标 - measureLine.半高,
        //            out hv_RowTrans1, out hv_ColTrans1);
        //        //ho_RegionLines3.Dispose();
        //        //HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //        //    hv_ColTrans1);    
        //        //HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //        //    hv_ColTrans1);
        //        //hWindow_F.DispObj(ho_RegionLines3);
        //        HOperatorSet.GenRectangle2(out HObject rectangle, measureLine.行坐标, measureLine.列坐标, measureLine.弧度, measureLine.半宽, measureLine.半高);
        //        hWindow_F.DispObj(rectangle, "green");

        //        #region 给参数赋值
        //        Line_INFO line_INFO = new Line_INFO(hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1);
        //        Metrology_INFO m_MetrologyInfo = new Metrology_INFO();
        //        m_MetrologyInfo.Length1 = measureLine.半宽;
        //        m_MetrologyInfo.Length2 = measureLine.半高 / 20;
        //        m_MetrologyInfo.Threshold = measureLine.阈值;
        //        m_MetrologyInfo.MeasureDis = measureLine.步长;
        //        m_MetrologyInfo.PointsOrder = 0;//cb_Direction.SelectedIndex;
        //        m_MetrologyInfo.Sigma = measureLine.滤波系数;
        //        string transition, select;
        //        switch (measureLine.过渡方式)
        //        {
        //            case Transition.白到黑: transition = "negative"; break;
        //            case Transition.黑到白: transition = "positive"; break;
        //            default: transition = "all"; break;
        //        }
        //        switch (measureLine.选择点)
        //        {
        //            case Select.第一个点: select = "first"; break;
        //            case Select.最后一个点: select = "last"; break;
        //            default: select = "all"; break;
        //        }
        //        //string mTransition = "negative";
        //        //string m_PointsOrder = "positive"; //传输点的方向是顺时针还是逆时针暂时还没有设计
        //        //string mSelect = "first";
        //        //mSelect = "strongest";//magical  增加最强边边缘
        //        //Measure_select = "strongest";//magical  增加最强边边缘
        //        m_MetrologyInfo.ParamName = new HTuple();
        //        m_MetrologyInfo.ParamName.Append("measure_transition");
        //        m_MetrologyInfo.ParamName.Append("measure_select");
        //        m_MetrologyInfo.ParamName.Append("measure_distance");
        //        //m_MetrologyInfo.ParamName.Append("max_num_iterations");
        //        //m_MetrologyInfo.ParamName.Append("measure_interpolation");
        //        m_MetrologyInfo.ParamValue = new HTuple();
        //        m_MetrologyInfo.ParamValue.Append(transition);
        //        m_MetrologyInfo.ParamValue.Append(select);
        //        m_MetrologyInfo.ParamValue.Append(m_MetrologyInfo.MeasureDis);
        //        #endregion
        //        HImage hImage = new HImage();
        //        HobjectToHimage(Image, ref hImage);
        //        //HTuple outR, outC;  HXLDCont outMeasureXLD; HRegion disableRegion = null;
        //        HRegion disableRegion = null;

        //        bool result = MeasureLine(hImage, line_INFO, m_MetrologyInfo,
        //                     out Line_INFO outLine, out HTuple outR, out HTuple outC, out HXLDCont outMeasureXLD, disableRegion);
        //        HXLDCont m_MeasureCross = new HXLDCont();
        //        //HXLDCont m_ResultXLD = new HXLDCont();
        //        m_MeasureCross.GenCrossContourXld(outR, outC, (HTuple)m_MetrologyInfo.Length2, new HTuple(outLine.Nx + new HTuple(30).TupleRad()));
        //        //m_ResultXLD.GenContourPolygonXld(new HTuple(outLine.StartY, outLine.EndY), new HTuple(outLine.StartX, outLine.EndX));
        //        //hWindow_F.DispObj(m_ResultXLD, "red");
        //        hWindow_F.DispObj(m_MeasureCross, "blue");
        //        hv_StartRow = outLine.StartY; hv_StartColumn = outLine.StartX;
        //        hv_EndRow = outLine.EndY; hv_EndColumn = outLine.EndX;
        //        HOperatorSet.GenRegionLine(out HObject LineInfo, hv_StartRow, hv_StartColumn, hv_EndRow, hv_EndColumn);
        //        hWindow_F.DispObj(LineInfo, "red");
        //        if (!result)
        //        {
        //            hv_StartRow = 0; hv_StartColumn = 0;
        //            hv_EndRow = 0; hv_EndColumn = 0;
        //        }
        //        return result;
        //    }
        //    catch (Exception e)
        //    {
        //        Tool.LogForm(e);
        //        Tool.LogForm("行坐标:" + measureLine.行坐标.ToString() + "列坐标:" + measureLine.列坐标.ToString() + "弧度:" + measureLine.弧度.ToString() + "半宽:" + measureLine.半宽.ToString() + "半高:" + measureLine.半高.ToString());
        //        hv_StartRow = 0; hv_StartColumn = 0;
        //        hv_EndRow = 0; hv_EndColumn = 0;
        //        return false;
        //    }
        //}

        /// <summary>
        /// 跟随找边
        /// </summary>
        /// <param name="Image"></param>
        /// <param name="hWindow_F"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <param name="measureLine"></param>
        /// <param name="hv_StartRow"></param>
        /// <param name="hv_StartColumn"></param>
        /// <param name="hv_EndRow"></param>
        /// <param name="hv_EndColumn"></param>
        /// <returns></returns>
        //public bool MeasureLineP(HObject Image, HWindow_F hWindow_F, double row, double col, MeasureLine measureLine, out HTuple hv_StartRow, out HTuple hv_StartColumn, out HTuple hv_EndRow, out HTuple hv_EndColumn)
        //{
        //    try
        //    {

        //        HObject ho_RegionLines3;
        //        HOperatorSet.GenEmptyObj(out ho_RegionLines3);
        //        HTuple hv_HomMat2DIdentity1, hv_HomMat2DRotate1, hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1;
        //        //测量矩形中线2 平行于边缘
        //        HOperatorSet.HomMat2dIdentity(out hv_HomMat2DIdentity1);
        //        HOperatorSet.HomMat2dRotate(hv_HomMat2DIdentity1, measureLine.弧度 - ((new HTuple(90)).TupleRad()
        //            ), row, col, out hv_HomMat2DRotate1);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, row, col + measureLine.半高,
        //            out hv_RowTrans, out hv_ColTrans);
        //        HOperatorSet.AffineTransPixel(hv_HomMat2DRotate1, row, col - measureLine.半高,
        //            out hv_RowTrans1, out hv_ColTrans1);
        //        //ho_RegionLines3.Dispose();
        //        //HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //        //    hv_ColTrans1);    
        //        //HOperatorSet.GenRegionLine(out ho_RegionLines3, hv_RowTrans, hv_ColTrans, hv_RowTrans1,
        //        //    hv_ColTrans1);
        //        //hWindow_F.DispObj(ho_RegionLines3);
        //        HOperatorSet.GenRectangle2(out HObject rectangle, row, col, measureLine.弧度, measureLine.半宽, measureLine.半高);
        //        hWindow_F.DispObj(rectangle, "green");

        //        #region 给参数赋值
        //        Line_INFO line_INFO = new Line_INFO(hv_RowTrans, hv_ColTrans, hv_RowTrans1, hv_ColTrans1);
        //        Metrology_INFO m_MetrologyInfo = new Metrology_INFO();
        //        m_MetrologyInfo.Length1 = measureLine.半宽;
        //        m_MetrologyInfo.Length2 = measureLine.半高 / 20;
        //        m_MetrologyInfo.Threshold = measureLine.阈值;
        //        m_MetrologyInfo.MeasureDis = measureLine.步长;
        //        m_MetrologyInfo.PointsOrder = 0;//cb_Direction.SelectedIndex;
        //        m_MetrologyInfo.Sigma = measureLine.滤波系数;
        //        string transition, select;
        //        switch (measureLine.过渡方式)
        //        {
        //            case Transition.白到黑: transition = "negative"; break;
        //            case Transition.黑到白: transition = "positive"; break;
        //            default: transition = "all"; break;
        //        }
        //        switch (measureLine.选择点)
        //        {
        //            case Select.第一个点: select = "first"; break;
        //            case Select.最后一个点: select = "last"; break;
        //            default: select = "all"; break;
        //        }
        //        //string mTransition = "negative";
        //        //string m_PointsOrder = "positive"; //传输点的方向是顺时针还是逆时针暂时还没有设计
        //        //string mSelect = "first";
        //        //mSelect = "strongest";//magical  增加最强边边缘
        //        //Measure_select = "strongest";//magical  增加最强边边缘
        //        m_MetrologyInfo.ParamName = new HTuple();
        //        m_MetrologyInfo.ParamName.Append("measure_transition");
        //        m_MetrologyInfo.ParamName.Append("measure_select");
        //        m_MetrologyInfo.ParamName.Append("measure_distance");
        //        //m_MetrologyInfo.ParamName.Append("max_num_iterations");
        //        //m_MetrologyInfo.ParamName.Append("measure_interpolation");
        //        m_MetrologyInfo.ParamValue = new HTuple();
        //        m_MetrologyInfo.ParamValue.Append(transition);
        //        m_MetrologyInfo.ParamValue.Append(select);
        //        m_MetrologyInfo.ParamValue.Append(m_MetrologyInfo.MeasureDis);
        //        #endregion
        //        HImage hImage = new HImage();
        //        HobjectToHimage(Image, ref hImage);
        //        //HTuple outR, outC;  HXLDCont outMeasureXLD; HRegion disableRegion = null;
        //        HRegion disableRegion = null;

        //        bool result = MeasureLine(hImage, line_INFO, m_MetrologyInfo,
        //                     out Line_INFO outLine, out HTuple outR, out HTuple outC, out HXLDCont outMeasureXLD, disableRegion);
        //        HXLDCont m_MeasureCross = new HXLDCont();
        //        //HXLDCont m_ResultXLD = new HXLDCont();
        //        m_MeasureCross.GenCrossContourXld(outR, outC, (HTuple)m_MetrologyInfo.Length2, new HTuple(outLine.Nx + new HTuple(30).TupleRad()));
        //        //m_ResultXLD.GenContourPolygonXld(new HTuple(outLine.StartY, outLine.EndY), new HTuple(outLine.StartX, outLine.EndX));
        //        //hWindow_F.DispObj(m_ResultXLD, "red");
        //        hWindow_F.DispObj(m_MeasureCross, "blue");
        //        hv_StartRow = outLine.StartY; hv_StartColumn = outLine.StartX;
        //        hv_EndRow = outLine.EndY; hv_EndColumn = outLine.EndX;
        //        HOperatorSet.GenRegionLine(out HObject LineInfo, hv_StartRow, hv_StartColumn, hv_EndRow, hv_EndColumn);
        //        hWindow_F.DispObj(LineInfo, "red");
        //        return result;
        //    }
        //    catch (Exception e)
        //    {
        //        Tool.LogForm(e);
        //        hv_StartRow = 0; hv_StartColumn = 0;
        //        hv_EndRow = 0; hv_EndColumn = 0;
        //        return false;
        //    }
        //}










        private static void HobjectToHimage(HObject hobject, ref HImage image)
        {
            HTuple pointer, type, width, height;
            HOperatorSet.GetImagePointer1(hobject, out pointer, out type, out width, out height);
            image.GenImage1(type, width, height, pointer);
        }
        /// <summary>
        /// 检测直线 增加屏蔽区域 magical20171028
        /// </summary>
        /// <param name="inImage">检测图像</param>
        /// <param name="inLine">输入检测直线区域</param>
        /// <param name="inMetrology">形态参数</param>
        /// <param name="outLine">输出直线</param>
        /// <param name="outR">输出行点</param>
        /// <param name="outC">输出列点</param>
        /// <param name="outMeasureXLD">输出检测轮廓</param>
        /// <param name="disableRegion">屏蔽区域 可选</param>
        /// <param name="isPaint">对屏蔽区域进行喷绘 可选</param>
        public static bool MeasureLine(HImage inImage, Line_INFO inLine, Metrology_INFO inMetrology, out Line_INFO outLine, out HTuple outR, out HTuple outC, out HXLDCont outMeasureXLD, HRegion disableRegion = null)
        {
            HMetrologyModel hMetrologyModel = new HMetrologyModel();
            try
            {
                outLine = new Line_INFO();
                HTuple lineResult = new HTuple();
                HTuple lineInfo = new HTuple();
                lineInfo.Append(new HTuple(new double[] { inLine.StartY, inLine.StartX, inLine.EndY, inLine.EndX }));

                //magical 20180405增加最强边的计算
                if (inMetrology.ParamValue[1] == "strongest")
                {
                    MeasureLine1D(inImage, inLine, inMetrology, out outLine, out outR, out outC, out outMeasureXLD, disableRegion);
                    return true;
                }

                hMetrologyModel.AddMetrologyObjectGeneric(new HTuple("line"), lineInfo, new HTuple(inMetrology.Length1),
                    new HTuple(inMetrology.Length2), new HTuple(inMetrology.Sigma), new HTuple(inMetrology.Threshold)
                    , inMetrology.ParamName, inMetrology.ParamValue);
                hMetrologyModel.SetMetrologyObjectParam(0, "min_score", 0.1);//降低直线拟合的最低得分,尽量使用halcon的拟合方法,因为VBA_Function.fitLine方法拟合的直线不准 magical 20171018


                if (disableRegion != null && disableRegion.IsInitialized())
                {
                    hMetrologyModel.ApplyMetrologyModel(inImage);

                    //单个测量区域 刚好 有一大半在屏蔽区域,一小部分在有效区域,这时候也会测出一个点,这个点在屏蔽区域内,导致精度损失约为1个像素左右.需要喷绘之后,再进行点是否在屏蔽区域判断
                    outMeasureXLD = hMetrologyModel.GetMetrologyObjectMeasures("all", "all", out outR, out outC);

                    List<double> tempOutR = new List<double>(), tempOutC = new List<double>();

                    for (int i = 0; i < outR.DArr.Length - 1; i++)
                    {
                        //0 表示没有包含
                        if (disableRegion.TestRegionPoint(outR[i].D, outC[i].D) == 0)
                        {
                            tempOutR.Add(outR[i].D);
                            tempOutC.Add(outC[i].D);
                        }
                    }
                    outR = new HTuple(tempOutR.ToArray());
                    outC = new HTuple(tempOutC.ToArray());
                }
                else
                {
                    hMetrologyModel.ApplyMetrologyModel(inImage);
                    outMeasureXLD = hMetrologyModel.GetMetrologyObjectMeasures("all", "all", out outR, out outC);
                }
                lineResult = hMetrologyModel.GetMetrologyObjectResult(new HTuple("all"), new HTuple("all"), new HTuple("result_type"), new HTuple("all_param"));
                if (lineResult.TupleLength() >= 4)
                {
                    outLine = new Line_INFO(lineResult[0].D, lineResult[1].D, lineResult[2].D, lineResult[3].D);
                }
                else
                {
                    if (fitLineByH(outR.ToDArr().ToList(), outC.ToDArr().ToList(), out outLine))
                        outLine = inLine;
                }

                hMetrologyModel.Dispose();
                return true;
            }
            catch (Exception ex)
            {
                inLine.StartY = 0; inLine.StartX = 0;
                inLine.EndY = 0; inLine.EndX = 0;
                outLine = inLine;
                outR = new HTuple();
                outC = new HTuple();
                outMeasureXLD = new HXLDCont();
                hMetrologyModel.Dispose();
                return false;
                //异常写入日志文件
                // MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 利用一维测量算子,检测直线.再利用halcon的拟合直线算法拟合直线 主要用于最强边缘的测量 magical20180405
        /// </summary>
        /// <param name="inImage"></param>
        /// <param name="inLine"></param>
        /// <param name="inMetrology"></param>
        /// <param name="outLine"></param>
        /// <param name="outR"></param>
        /// <param name="outC"></param>
        /// <param name="outMeasureXLD"></param>
        /// <param name="disableRegion"></param>
        /// <param name="isPaint"></param>
        public static void MeasureLine1D(HImage inImage, Line_INFO inLine, Metrology_INFO inMetrology, out Line_INFO outLine, out HTuple outR, out HTuple outC, out HXLDCont outMeasureXLD, HRegion disableRegion = null, bool isPaint = true)
        {

            outLine = inLine;
            outR = new HTuple();
            outC = new HTuple();
            List<double> outRList = new List<double>();
            List<double> outCList = new List<double>();
            HImage tempImage;
            if (disableRegion != null && disableRegion.IsInitialized())
            {
                //将屏蔽区域喷绘为0,这样就无法测量到点 magical 20171028
                tempImage = disableRegion.PaintRegion(inImage, 0d, "fill");
            }
            else
            {
                tempImage = inImage;
            }

            //注意下这里的角度
            double angle = HMisc.AngleLx(inLine.StartY, inLine.StartX, inLine.EndY, inLine.EndX);
            int pointsNum = (int)((HMisc.DistancePp(inLine.StartY, inLine.StartX, inLine.EndY, inLine.EndX) - 2 * inMetrology.Length2) / inMetrology.MeasureDis) + 1;
            double newMeasureDis = (HMisc.DistancePp(inLine.StartY, inLine.StartX, inLine.EndY, inLine.EndX) - 2 * inMetrology.Length2) / pointsNum;
            double rectRowC, rectColC;

            outMeasureXLD = new HXLDCont();
            outMeasureXLD.GenEmptyObj();
            for (int i = 0; i <= pointsNum; i++)
            {
                //rectRowC = inLine.StartY + (((inLine.EndY - inLine.StartY) * (i + 1)) / (pointsNum)) + inMetrology.Length2*Math.Sin(angle);
                //rectColC = inLine.StartX + (((inLine.EndX - inLine.StartX) * (i )) / (pointsNum))+ inMetrology.Length2 * Math.Cos(angle);
                rectRowC = inLine.StartY + (inMetrology.Length2 - i * newMeasureDis) * Math.Sin(angle);
                rectColC = inLine.StartX + (inMetrology.Length2 + i * newMeasureDis) * Math.Cos(angle);



                HXLDCont tempRect = new HXLDCont();
                tempRect.GenRectangle2ContourXld(rectRowC, rectColC, angle - Math.PI / 2, inMetrology.Length1, inMetrology.Length2);
                outMeasureXLD = outMeasureXLD.ConcatObj(tempRect);


                HMeasure mea = new HMeasure();
                int width, height;
                inImage.GetImageSize(out width, out height);
                mea.GenMeasureRectangle2(rectRowC, rectColC, angle - Math.PI / 2, inMetrology.Length1, inMetrology.Length2, width, height, "nearest_neighbor");
                HTuple rowEdge, columnEdge, amplitude, distance;
                mea.MeasurePos(tempImage, 1, inMetrology.Threshold, inMetrology.ParamValue[0], "all", out rowEdge, out columnEdge, out amplitude, out distance);

                if (amplitude != null & amplitude.Length > 0)
                {
                    // amplitude.TupleSort();
                    HTuple HIndex = amplitude.TupleAbs().TupleSortIndex();
                    outRList.Add(rowEdge[HIndex[HIndex.Length - 1].I]);
                    outCList.Add(columnEdge[HIndex[HIndex.Length - 1].I]);
                }

                mea.Dispose();
            }
            outR = new HTuple(outRList.ToArray());
            outC = new HTuple(outCList.ToArray());

            if (disableRegion != null && disableRegion.IsInitialized())
            {
                List<double> tempOutR = new List<double>(), tempOutC = new List<double>();
                for (int i = 0; i < outR.DArr.Length - 1; i++)
                {
                    //0 表示没有包含
                    if (disableRegion.TestRegionPoint(outR[i].D, outC[i].D) == 0)
                    {
                        tempOutR.Add(outR[i].D);
                        tempOutC.Add(outC[i].D);
                    }
                }
                outR = new HTuple(tempOutR.ToArray());
                outC = new HTuple(tempOutC.ToArray());
            }

            if (outR.Length > 0)
            {
                fitLineByH(outRList, outCList, out outLine);
            }
            else
            {
                outLine = inLine;
            }

        }

        /// <summary>
        /// /使用halcon的拟合直线算法,比fitLine更准确,因为有其自己的剔除异常点算法
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="cols"></param>
        /// <param name="line"></param>
        /// <returns>结果直线</returns>
        public static bool fitLineByH(List<Double> rows, List<Double> cols, out Line_INFO line)
        {
            line = new Line_INFO();
            try
            {
                SortPairs(ref rows, ref cols);
                double rowBegin, colBegin, rowEnd, colEnd, nr, nc, dist;
                HXLDCont lineXLD = new HXLDCont(new HTuple(rows.ToArray()), new HTuple(cols.ToArray()));
                lineXLD.FitLineContourXld("tukey", -1, 0, 5, 2, out rowBegin, out colBegin, out rowEnd, out colEnd, out nr, out nc, out dist);//tukey剔除算法为halcon推荐算法
                line = new Line_INFO(rowBegin, colBegin, rowEnd, colEnd);
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }

        /// <summary>
        /// 点排序
        /// </summary>
        /// <param name="hv_T1"></param>
        /// <param name="hv_T2"></param>
        public static void SortPairs(ref HTuple hv_T1, ref HTuple hv_T2)
        {
            HTuple hv_Sorted1 = new HTuple();
            HTuple hv_Sorted2 = new HTuple();
            HTuple hv_SortMode = new HTuple();
            HTuple hv_Indices1 = new HTuple(), hv_Indices2 = new HTuple();
            if ((hv_T1.TupleMax().D - hv_T1.TupleMin().D) > (hv_T2.TupleMax().D - hv_T2.TupleMin().D))
                hv_SortMode = new HTuple("1");
            else
                hv_SortMode = new HTuple("2");
            if ((int)((new HTuple(hv_SortMode.TupleEqual("1"))).TupleOr(new HTuple(hv_SortMode.TupleEqual(
                1)))) != 0)
            {
                HOperatorSet.TupleSortIndex(hv_T1, out hv_Indices1);
                hv_Sorted1 = hv_T1.TupleSelect(hv_Indices1);
                hv_Sorted2 = hv_T2.TupleSelect(hv_Indices1);
            }
            else if ((int)((new HTuple((new HTuple(hv_SortMode.TupleEqual("column"))).TupleOr(
                new HTuple(hv_SortMode.TupleEqual("2"))))).TupleOr(new HTuple(hv_SortMode.TupleEqual(
                2)))) != 0)
            {
                HOperatorSet.TupleSortIndex(hv_T2, out hv_Indices2);
                hv_Sorted1 = hv_T1.TupleSelect(hv_Indices2);
                hv_Sorted2 = hv_T2.TupleSelect(hv_Indices2);
            }
            hv_T1 = hv_Sorted1;
            hv_T2 = hv_Sorted2;
        }
        /// <summary>
        /// 点排序
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="cols"></param>
        public static void SortPairs(ref List<double> rows, ref List<double> cols)
        {
            HTuple hv_T1 = new HTuple(rows.ToArray());
            HTuple hv_T2 = new HTuple(cols.ToArray());
            //相同的方法 直接使用htuple返回结果
            SortPairs(ref hv_T1, ref hv_T2);
            rows = hv_T1.ToDArr().ToList();
            cols = hv_T2.ToDArr().ToList();
            return;

            //HTuple hv_Sorted1 = new HTuple();
            //HTuple hv_Sorted2 = new HTuple();
            //HTuple hv_SortMode = new HTuple();
            //HTuple hv_Indices1 = new HTuple(), hv_Indices2 = new HTuple();
            //if ((rows.Max() - rows.Min()) > (cols.Max() - cols.Min()))
            //    hv_SortMode = new HTuple("1");
            //else
            //    hv_SortMode = new HTuple("2");
            //if ((int)((new HTuple(hv_SortMode.TupleEqual("1"))).TupleOr(new HTuple(hv_SortMode.TupleEqual(
            //    1)))) != 0)
            //{
            //    HOperatorSet.TupleSortIndex(hv_T1, out hv_Indices1);
            //    hv_Sorted1 = hv_T1.TupleSelect(hv_Indices1);
            //    hv_Sorted2 = hv_T2.TupleSelect(hv_Indices1);
            //}
            //else if ((int)((new HTuple((new HTuple(hv_SortMode.TupleEqual("column"))).TupleOr(
            //    new HTuple(hv_SortMode.TupleEqual("2"))))).TupleOr(new HTuple(hv_SortMode.TupleEqual(
            //    2)))) != 0)
            //{
            //    HOperatorSet.TupleSortIndex(hv_T2, out hv_Indices2);
            //    hv_Sorted1 = hv_T1.TupleSelect(hv_Indices2);
            //    hv_Sorted2 = hv_T2.TupleSelect(hv_Indices2);
            //}
            //rows = hv_Sorted1.ToDArr().ToList();
            //cols = hv_Sorted2.ToDArr().ToList();
        }
        public static void rake_edge(HObject ho_Image, HTuple hv_CenterRow, HTuple hv_CenterCol,
             HTuple hv_Phi, HTuple hv_Length1, HTuple hv_Length2, HTuple hv_Step, HTuple hv_Sigma,
             HTuple hv_Threshold, HTuple hv_Transition, HTuple hv_Select, HTuple hv_ShowSearchArea,
             HTuple hv_ShowSearchLine, HTuple hv_ShowResultPoints, HTuple hv_R1, HTuple hv_C1,
             out HTuple hv_RowBegin, out HTuple hv_ColBegin, out HTuple hv_RowEnd, out HTuple hv_ColEnd,
             out HTuple hv_RowLine, out HTuple hv_ColLine)
        {




            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_DupImage, ho_Arrow = null, ho_Rectangle = null;
            HObject ho_Rectangle1 = null, ho_Contour = null;

            // Local copy input parameter variables 
            HObject ho_Image_COPY_INP_TMP;
            ho_Image_COPY_INP_TMP = new HObject(ho_Image);



            // Local control variables 

            HTuple hv_i = new HTuple(), hv_Width = new HTuple();
            HTuple hv_Height = new HTuple(), hv_Index = new HTuple();
            HTuple hv_MeasureHandle1 = new HTuple(), hv_RowEdge = new HTuple();
            HTuple hv_ColumnEdge = new HTuple(), hv_Amplitude = new HTuple();
            HTuple hv_Distance = new HTuple(), hv_Length = new HTuple();
            HTuple hv_RL = new HTuple(), hv_CL = new HTuple(), hv_Count = new HTuple();
            HTuple hv_RowsNew = new HTuple(), hv_ColsNew = new HTuple();
            HTuple hv_Nums_Min = new HTuple(), hv_M_Row1 = new HTuple();
            HTuple hv_M_Col1 = new HTuple(), hv_D_Row1 = new HTuple();
            HTuple hv_D_Col1 = new HTuple(), hv_Nr = new HTuple();
            HTuple hv_Nc = new HTuple(), hv_Dist = new HTuple();
            HTuple hv_ShowSearchLine_COPY_INP_TMP = new HTuple(hv_ShowSearchLine);

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_DupImage);
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            hv_RowBegin = new HTuple();
            hv_ColBegin = new HTuple();
            hv_RowEnd = new HTuple();
            hv_ColEnd = new HTuple();
            hv_RowLine = new HTuple();
            hv_ColLine = new HTuple();
            try
            {

                //*************************输入
                //Image:输入图像
                //CenterRow:输入矩形框的行中心
                //CenterCol:输入矩形框的列中心
                //Phi:输入矩形框的角度
                //Length1:输入矩形框的宽度
                //Length2:输入矩形框的高度
                //Step:扫描间隔
                //Sigma:高期平滑度
                //Threshold:最小边缘过渡
                //Transition:边缘提取方式,'negative'从白到黑,'positive'从黑到白,'all'都可以
                //Select:选取点方式,'first'第一个,'last'最后一个,'all'两者都有
                //ShowSearchArea:是否显示搜索框
                //ShowSearchLine:是否显示搜索线
                //ShowResultPoints:是否显示结果点
                //
                //************************输出
                //RowBegin:边的起始行
                //ColBegin:边的起始列
                //RowEnd:边的终点行
                //ColEnd:边的终点列
                //
                //是否显示搜索区域
                ho_DupImage.Dispose();
                HOperatorSet.CopyImage(ho_Image_COPY_INP_TMP, out ho_DupImage);
                for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_CenterRow.TupleLength())) - 1); hv_i = (int)hv_i + 1)
                {
                    if ((int)(new HTuple(hv_ShowSearchArea.TupleEqual("TRUE"))) != 0)
                    {
                        //在搜索框外显示角度指示箭头
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_Arrow.Dispose();
                            //gen_arrow_contour_xld(out ho_Arrow, (hv_CenterRow.TupleSelect(hv_i)) + ((((hv_Phi.TupleSelect(
                            //    hv_i))).TupleSin()) * ((hv_Length1.TupleSelect(hv_i)) + 20)), (hv_CenterCol.TupleSelect(
                            //    hv_i)) - ((((hv_Phi.TupleSelect(hv_i))).TupleCos()) * ((hv_Length1.TupleSelect(
                            //    hv_i)) + 20)), (hv_CenterRow.TupleSelect(hv_i)) + ((((hv_Phi.TupleSelect(
                            //    hv_i))).TupleSin()) * (hv_Length1.TupleSelect(hv_i))), (hv_CenterCol.TupleSelect(
                            //    hv_i)) - ((((hv_Phi.TupleSelect(hv_i))).TupleCos()) * (hv_Length1.TupleSelect(
                            //    hv_i))), 10, 10);
                        }
                        //生成搜索框
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_Rectangle.Dispose();
                            HOperatorSet.GenRectangle2(out ho_Rectangle, hv_CenterRow.TupleSelect(hv_i),
                                hv_CenterCol.TupleSelect(hv_i), hv_Phi.TupleSelect(hv_i), hv_Length1.TupleSelect(
                                hv_i), hv_Length2.TupleSelect(hv_i));
                        }
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                        }
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 2);
                        }
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.DispObj(ho_Arrow, HDevWindowStack.GetActive());
                        }
                        if (HDevWindowStack.IsOpen())
                        {
                            HOperatorSet.DispObj(ho_Rectangle, HDevWindowStack.GetActive());
                        }
                    }
                }


                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 1);
                }
                //初始化结果点的行列
                hv_RowLine.Dispose();
                hv_RowLine = new HTuple();
                hv_ColLine.Dispose();
                hv_ColLine = new HTuple();
                hv_Width.Dispose(); hv_Height.Dispose();
                HOperatorSet.GetImageSize(ho_Image_COPY_INP_TMP, out hv_Width, out hv_Height);
                //
                //循环扫描点
                for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_Length2.TupleLength())) - 1); hv_i = (int)hv_i + 1)
                {
                    HTuple end_val47 = ((hv_Length2.TupleSelect(
                        hv_i)) * 2) / hv_Step;
                    HTuple step_val47 = 1;
                    for (hv_Index = 0; hv_Index.Continue(end_val47, step_val47); hv_Index = hv_Index.TupleAdd(step_val47))
                    {
                        //生成测量矩形,宽度为0,即为一条直线
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_MeasureHandle1.Dispose();
                            HOperatorSet.GenMeasureRectangle2((hv_CenterRow.TupleSelect(hv_i)) - ((((hv_Phi.TupleSelect(
                                hv_i))).TupleCos()) * ((hv_Length2.TupleSelect(hv_i)) - (hv_Step * hv_Index))),
                                (hv_CenterCol.TupleSelect(hv_i)) - ((((hv_Phi.TupleSelect(hv_i))).TupleSin()
                                ) * ((hv_Length2.TupleSelect(hv_i)) - (hv_Step * hv_Index))), hv_Phi.TupleSelect(
                                hv_i), hv_Length1.TupleSelect(hv_i), hv_Step, hv_Width, hv_Height,
                                "nearest_neighbor", out hv_MeasureHandle1);
                        }
                        //是否显示搜索线
                        hv_ShowSearchLine_COPY_INP_TMP.Dispose();
                        hv_ShowSearchLine_COPY_INP_TMP = "TRUE";
                        if ((int)(new HTuple(hv_ShowSearchLine_COPY_INP_TMP.TupleEqual("TRUE"))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                ho_Rectangle1.Dispose();
                                HOperatorSet.GenRectangle2(out ho_Rectangle1, (hv_CenterRow.TupleSelect(
                                    hv_i)) - ((((hv_Phi.TupleSelect(hv_i))).TupleCos()) * ((hv_Length2.TupleSelect(
                                    hv_i)) - (hv_Step * hv_Index))), (hv_CenterCol.TupleSelect(hv_i)) - ((((hv_Phi.TupleSelect(
                                    hv_i))).TupleSin()) * ((hv_Length2.TupleSelect(hv_i)) - (hv_Step * hv_Index))),
                                    hv_Phi.TupleSelect(hv_i), hv_Length1.TupleSelect(hv_i), hv_Step);
                            }
                            if (HDevWindowStack.IsOpen())
                            {
                                HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
                            }
                            if (HDevWindowStack.IsOpen())
                            {
                                //dev_display (Rectangle1)
                            }
                        }
                        //
                        //测量点
                        {
                            HObject ExpTmpOutVar_0;
                            HOperatorSet.CopyObj(ho_Image_COPY_INP_TMP, out ExpTmpOutVar_0, 1, 1);
                            ho_Image_COPY_INP_TMP.Dispose();
                            ho_Image_COPY_INP_TMP = ExpTmpOutVar_0;
                        }
                        hv_RowEdge.Dispose(); hv_ColumnEdge.Dispose(); hv_Amplitude.Dispose(); hv_Distance.Dispose();
                        HOperatorSet.MeasurePos(ho_Image_COPY_INP_TMP, hv_MeasureHandle1, hv_Sigma,
                            hv_Threshold, hv_Transition, hv_Select, out hv_RowEdge, out hv_ColumnEdge,
                            out hv_Amplitude, out hv_Distance);
                        HOperatorSet.CloseMeasure(hv_MeasureHandle1);
                        //是否显示结果点
                        if ((int)(new HTuple(hv_ShowResultPoints.TupleEqual("TRUE"))) != 0)
                        {
                            //gen_circle (Circle, RowEdge, ColumnEdge, 1)
                            hv_Length.Dispose();
                            HOperatorSet.TupleLength(hv_RowEdge, out hv_Length);
                            if ((int)(new HTuple(hv_Length.TupleGreater(0))) != 0)
                            {

                                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                                {
                                    {
                                        HTuple
                                          ExpTmpLocalVar_RowLine = hv_RowLine.TupleConcat(
                                            hv_RowEdge);
                                        hv_RowLine.Dispose();
                                        hv_RowLine = ExpTmpLocalVar_RowLine;
                                    }
                                }
                                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                                {
                                    {
                                        HTuple
                                          ExpTmpLocalVar_ColLine = hv_ColLine.TupleConcat(
                                            hv_ColumnEdge);
                                        hv_ColLine.Dispose();
                                        hv_ColLine = ExpTmpLocalVar_ColLine;
                                    }
                                }
                                //生成十字架
                                //
                                //
                            }
                        }
                        //
                    }
                }


                //计算结果点的行列个数
                hv_RL.Dispose();
                HOperatorSet.TupleLength(hv_RowLine, out hv_RL);
                hv_CL.Dispose();
                HOperatorSet.TupleLength(hv_RowLine, out hv_CL);
                //
                //*剔除远离点**
                hv_Count.Dispose();
                hv_Count = 0;
                hv_RowsNew.Dispose();
                hv_RowsNew = new HTuple();
                hv_ColsNew.Dispose();
                hv_ColsNew = new HTuple();
                hv_Nums_Min.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Nums_Min = hv_Index / 5;
                }
                if ((int)((new HTuple(hv_RL.TupleGreater(hv_Nums_Min))).TupleAnd(new HTuple(hv_CL.TupleGreater(
                    hv_Nums_Min)))) != 0)
                {
                    //

                    hv_M_Row1.Dispose();
                    HOperatorSet.TupleMean(hv_RowLine, out hv_M_Row1);
                    hv_M_Col1.Dispose();
                    HOperatorSet.TupleMean(hv_ColLine, out hv_M_Col1);
                    hv_D_Row1.Dispose();
                    HOperatorSet.TupleDeviation(hv_RowLine, out hv_D_Row1);
                    hv_D_Col1.Dispose();
                    HOperatorSet.TupleDeviation(hv_ColLine, out hv_D_Col1);

                    //生成Contour
                    ho_Contour.Dispose();
                    HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowLine, hv_ColLine);
                    //
                    //拟合直线,参数可以更改或改成接口
                    hv_RowBegin.Dispose(); hv_ColBegin.Dispose(); hv_RowEnd.Dispose(); hv_ColEnd.Dispose(); hv_Nr.Dispose(); hv_Nc.Dispose(); hv_Dist.Dispose();
                    HOperatorSet.FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, out hv_RowBegin,
                        out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc,
                        out hv_Dist);
                    //结果点的行个数或列个数>=2拟合,防止报错
                }
                else
                {
                    //置为-1,防止输出时画直线报错
                    hv_RowBegin.Dispose();
                    hv_RowBegin = -1;
                    hv_ColBegin.Dispose();
                    hv_ColBegin = -1;
                    hv_RowEnd.Dispose();
                    hv_RowEnd = -1;
                    hv_ColEnd.Dispose();
                    hv_ColEnd = -1;
                }
                //



                ho_Image_COPY_INP_TMP.Dispose();
                ho_DupImage.Dispose();
                ho_Arrow.Dispose();
                ho_Rectangle.Dispose();
                ho_Rectangle1.Dispose();
                ho_Contour.Dispose();

                hv_ShowSearchLine_COPY_INP_TMP.Dispose();
                hv_i.Dispose();
                hv_Width.Dispose();
                hv_Height.Dispose();
                hv_Index.Dispose();
                hv_MeasureHandle1.Dispose();
                hv_RowEdge.Dispose();
                hv_ColumnEdge.Dispose();
                hv_Amplitude.Dispose();
                hv_Distance.Dispose();
                hv_Length.Dispose();
                hv_RL.Dispose();
                hv_CL.Dispose();
                hv_Count.Dispose();
                hv_RowsNew.Dispose();
                hv_ColsNew.Dispose();
                hv_Nums_Min.Dispose();
                hv_M_Row1.Dispose();
                hv_M_Col1.Dispose();
                hv_D_Row1.Dispose();
                hv_D_Col1.Dispose();
                hv_Nr.Dispose();
                hv_Nc.Dispose();
                hv_Dist.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_Image_COPY_INP_TMP.Dispose();
                ho_DupImage.Dispose();
                ho_Arrow.Dispose();
                ho_Rectangle.Dispose();
                ho_Rectangle1.Dispose();
                ho_Contour.Dispose();

                hv_ShowSearchLine_COPY_INP_TMP.Dispose();
                hv_i.Dispose();
                hv_Width.Dispose();
                hv_Height.Dispose();
                hv_Index.Dispose();
                hv_MeasureHandle1.Dispose();
                hv_RowEdge.Dispose();
                hv_ColumnEdge.Dispose();
                hv_Amplitude.Dispose();
                hv_Distance.Dispose();
                hv_Length.Dispose();
                hv_RL.Dispose();
                hv_CL.Dispose();
                hv_Count.Dispose();
                hv_RowsNew.Dispose();
                hv_ColsNew.Dispose();
                hv_Nums_Min.Dispose();
                hv_M_Row1.Dispose();
                hv_M_Col1.Dispose();
                hv_D_Row1.Dispose();
                hv_D_Col1.Dispose();
                hv_Nr.Dispose();
                hv_Nc.Dispose();
                hv_Dist.Dispose();

                throw HDevExpDefaultException;
            }
        }


        public static void Detect_QD(HObject ho_DupImage, HTuple hv_Parms, HTuple hv_WindowHandle,
   out HTuple hv_Row_QD, out HTuple hv_Col_QD, out HTuple hv_Lines, out HObject ho_Line)
        {

            #region 
            // Local iconic variables 

            HObject ho_ContCircle_Cor, ho_Rectangle2, ho_Contour_U; ho_Line = new HObject();
            HObject ho_Contour_L, ho_Contour_YH = null, ho_Region_YH = null;
            HObject ho_Rectangle_YH = null, ho_Rectangle = null, ho_ContoursSplit = null;
            HObject ho_Contour = null, ho_ContCircle = null;

            // Local control variables 

            HTuple hv_Row1 = new HTuple(), hv_Col1 = new HTuple(); hv_Lines = new HTuple();
            HTuple hv_Phi1 = new HTuple(), hv_Length11 = new HTuple();
            HTuple hv_Length21 = new HTuple(), hv_Step = new HTuple(), hv_k = new HTuple(), hv_b = new HTuple();
            HTuple hv_Sigma = new HTuple(), hv_Threshold = new HTuple();
            HTuple hv_Transition = new HTuple(), hv_Orient = new HTuple();
            HTuple hv_V_Dist = new HTuple(), hv_H_Dist = new HTuple();
            HTuple hv_Rate_H = new HTuple(), hv_Width = new HTuple();
            HTuple hv_Height = new HTuple(), hv_RowBegin1_U = new HTuple();
            HTuple hv_ColBegin1_U = new HTuple(), hv_RowEnd1_U = new HTuple();
            HTuple hv_ColEnd1_U = new HTuple(), hv_Row_Line = new HTuple();
            HTuple hv_Col_Line = new HTuple(), hv_Row2 = new HTuple();
            HTuple hv_Col2 = new HTuple(), hv_Phi2 = new HTuple();
            HTuple hv_Angle = new HTuple(), hv_Phi = new HTuple();
            HTuple hv_c1 = new HTuple(), hv_r1 = new HTuple(), hv_c2 = new HTuple();
            HTuple hv_r2 = new HTuple(), hv_c = new HTuple(), hv_r = new HTuple();
            HTuple hv_Mid_Row = new HTuple(), hv_Mid_Col = new HTuple();
            HTuple hv_H_Length = new HTuple(), hv_V_Length = new HTuple();
            HTuple hv_RowBegin = new HTuple(), hv_ColBegin = new HTuple();
            HTuple hv_RowEnd = new HTuple(), hv_ColEnd = new HTuple();
            HTuple hv_RowLine = new HTuple(), hv_ColLine = new HTuple();
            HTuple hv_Min = new HTuple(), hv_Row = new HTuple(), hv_Column = new HTuple();
            HTuple hv_Radius = new HTuple(), hv_StartPhi = new HTuple();
            HTuple hv_EndPhi = new HTuple(), hv_PointOrder = new HTuple();
            HTuple hv_Column2 = new HTuple(), hv_IsOverlapping = new HTuple();
            HTuple hv_i = new HTuple(), hv_IsParallel = new HTuple();

            HTuple hv_RowLines = new HTuple();
            HTuple hv_ColLines = new HTuple(); HTuple hv_Median = new HTuple(), hv_Indices_M = new HTuple();
            HTuple hv_Max = new HTuple(), hv_Indices_Min = new HTuple(); HTuple hv_Indices_Max = new HTuple(), hv_Length = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_ContCircle_Cor);

            HOperatorSet.GenEmptyObj(out ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out ho_Contour_U);
            HOperatorSet.GenEmptyObj(out ho_Contour_L);
            HOperatorSet.GenEmptyObj(out ho_Contour_YH);
            HOperatorSet.GenEmptyObj(out ho_Region_YH);
            HOperatorSet.GenEmptyObj(out ho_Rectangle_YH);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            HOperatorSet.GenEmptyObj(out ho_ContCircle);
            hv_Row_QD = new HTuple();
            hv_Col_QD = new HTuple();

            #endregion 
            try
            {
                //配置参数*
                //参数配置*               
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_RowBegin1_U = hv_Parms.TupleSelect(
                        0);
                }
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_ColBegin1_U = hv_Parms.TupleSelect(
                        1);
                }
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_RowEnd1_U = hv_Parms.TupleSelect(
                        2);
                }
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_ColEnd1_U = hv_Parms.TupleSelect(
                        3);
                }

                //Orient=1圆弧向左，Orient=2圆弧向右*
                hv_Orient.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Orient = hv_Parms.TupleSelect(
                        4);
                }
                //圆弧区域，直线竖向移动*
                hv_V_Dist.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_V_Dist = hv_Parms.TupleSelect(
                        5);
                }
                //圆弧区域，直线横向移动*
                hv_H_Dist.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_H_Dist = hv_Parms.TupleSelect(
                        6);
                }

                //圆弧外接矩形框高比例*
                hv_Rate_H.Dispose();
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Rate_H = hv_Parms.TupleSelect(
                        7);
                }

                //圆弧外接矩形框高比例*               
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_Transition = hv_Parms.TupleSelect(
                        8);
                }

                //初始化切点坐标*
                hv_Row_QD.Dispose();
                hv_Row_QD = -1;
                hv_Col_QD.Dispose();
                hv_Col_QD = -1;


                hv_Width.Dispose(); hv_Height.Dispose();
                HOperatorSet.GetImageSize(ho_DupImage, out hv_Width, out hv_Height);

                //寻找圆弧部分区域，由横边向下平移一定距离*
                if ((int)(new HTuple(hv_RowBegin1_U.TupleGreater(0))) != 0)
                {
                    //横边直线角度*
                    if ((int)(new HTuple(hv_ColBegin1_U.TupleLess(hv_ColEnd1_U))) != 0)
                    {
                        hv_Angle.Dispose();
                        HOperatorSet.AngleLx(hv_RowBegin1_U, hv_ColBegin1_U, hv_RowEnd1_U, hv_ColEnd1_U,
                            out hv_Angle);
                    }
                    else
                    {
                        hv_Angle.Dispose();
                        HOperatorSet.AngleLx(hv_RowEnd1_U, hv_ColEnd1_U, hv_RowBegin1_U, hv_ColBegin1_U,
                            out hv_Angle);
                    }
                    hv_Phi.Dispose();
                    hv_Phi = new HTuple(hv_Angle);
                    //横边向下平移一定距离V_Dist，构成矩形*
                    hv_c1.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_c1 = hv_ColBegin1_U + (hv_V_Dist * (hv_Phi.TupleSin()
                            ));
                    }
                    hv_r1.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_r1 = hv_RowBegin1_U + (hv_V_Dist * (hv_Phi.TupleCos()
                            ));
                    }
                    hv_c2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_c2 = hv_ColEnd1_U + (hv_V_Dist * (hv_Phi.TupleSin()
                            ));
                    }
                    hv_r2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_r2 = hv_RowEnd1_U + (hv_V_Dist * (hv_Phi.TupleCos()
                            ));
                    }
                    if ((int)(new HTuple(hv_ColBegin1_U.TupleLess(hv_ColEnd1_U))) != 0)
                    {
                        hv_c.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_c = (hv_c2 + hv_ColEnd1_U) * 0.5;
                        }
                        hv_r.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_r = (hv_r2 + hv_RowEnd1_U) * 0.5;
                        }
                    }
                    else
                    {
                        hv_c.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_c = (hv_c1 + hv_ColBegin1_U) * 0.5;
                        }
                        hv_r.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_r = (hv_r1 + hv_RowBegin1_U) * 0.5;
                        }
                    }
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Contour_YH.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_Contour_YH, ((((hv_r1.TupleConcat(
                            hv_r2))).TupleConcat(hv_RowEnd1_U))).TupleConcat(hv_RowBegin1_U), ((((hv_c1.TupleConcat(
                            hv_c2))).TupleConcat(hv_ColEnd1_U))).TupleConcat(hv_ColBegin1_U));
                    }
                    ho_Region_YH.Dispose();
                    HOperatorSet.GenRegionContourXld(ho_Contour_YH, out ho_Region_YH, "filled");
                    hv_Mid_Row.Dispose(); hv_Mid_Col.Dispose(); hv_Phi.Dispose(); hv_H_Length.Dispose(); hv_V_Length.Dispose();
                    HOperatorSet.SmallestRectangle2(ho_Region_YH, out hv_Mid_Row, out hv_Mid_Col,
                        out hv_Phi, out hv_H_Length, out hv_V_Length);
                    ho_Rectangle_YH.Dispose();
                    HOperatorSet.GenRectangle2(out ho_Rectangle_YH, hv_Mid_Row, hv_Mid_Col, hv_Phi,
                        hv_H_Length, hv_V_Length);


                    //为使得极片横边与圆有交点并且极片位置有偏移时，能够兼容，将直线进行延长*
                    if ((int)(new HTuple(hv_Orient.TupleEqual(1))) != 0)
                    {
                        hv_k.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_k = (hv_RowBegin1_U - hv_RowEnd1_U) / (hv_ColBegin1_U - hv_ColEnd1_U);
                        }
                        hv_b.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_b = hv_RowEnd1_U - (hv_k * hv_ColEnd1_U);
                        }

                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_ColBegin1_U = hv_Width * 0.5;
                        }

                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_RowBegin1_U = (hv_k * hv_ColBegin1_U) + hv_b;
                        }
                        if ((int)(new HTuple(hv_Angle.TupleGreater(0))) != 0)
                        {
                            hv_Phi.Dispose();
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Phi = hv_Angle - 3.1415;
                            }
                        }
                        else
                        {
                            hv_Phi.Dispose();
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Phi = 3.1415 - (hv_Angle.TupleAbs()
                                    );
                            }
                        }
                    }
                    else
                    {
                        hv_k.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_k = (hv_RowEnd1_U - hv_RowBegin1_U) / (hv_ColEnd1_U - hv_ColBegin1_U);
                        }
                        hv_b.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_b = hv_RowEnd1_U - (hv_k * hv_ColEnd1_U);
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_ColEnd1_U = hv_Width * 0.5;
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_RowEnd1_U = (hv_k * hv_ColEnd1_U) + hv_b;
                        }
                    }

                    //为使得极片横边与圆有交点并且极片位置有偏移时，能够兼容，将直线进行延长*
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Contour_U.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_Contour_U, hv_RowBegin1_U.TupleConcat(
                            hv_RowEnd1_U), hv_ColBegin1_U.TupleConcat(hv_ColEnd1_U));
                    }

                    //if ((int)(new HTuple(hv_Orient.TupleEqual(1))) != 0)
                    //{
                    //    if ((int)(new HTuple(hv_Angle.TupleGreater(0))) != 0)
                    //    {
                    //        hv_Phi.Dispose();
                    //        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    //        {
                    //            hv_Phi = hv_Angle - 3.1415;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        hv_Phi.Dispose();
                    //        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    //        {
                    //            hv_Phi = 3.1415 - (hv_Angle.TupleAbs()
                    //                );
                    //        }
                    //    }
                    //}
                    //圆弧外接矩形区域*

                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Rectangle.Dispose();
                        //if ((int)(new HTuple(hv_Orient.TupleEqual(1))) != 0)
                        //{
                        HOperatorSet.GenRectangle2(out ho_Rectangle, hv_r, hv_c + hv_H_Dist, (hv_Angle), 130,
                       hv_V_Length * hv_Rate_H);
                        //}
                        //else
                        //{
                        //    HOperatorSet.GenRectangle2(out ho_Rectangle, hv_r, hv_c + hv_H_Dist, (hv_Angle.D + 0.26), 130,
                        //   hv_V_Length * hv_Rate_H);
                        //}

                        HOperatorSet.DispObj(ho_Rectangle, hv_WindowHandle);
                        //将找圆弧框的参数传出去，用于缩放时显示
                        //hv_Lines[0] = hv_r; hv_Lines[1] = hv_c + hv_H_Dist; hv_Lines[2] = hv_Angle; hv_Lines[3] = 100; hv_Lines[4] = hv_V_Length * hv_Rate_H;

                    }
                    //获取圆弧一系列点*
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowBegin.Dispose(); hv_ColBegin.Dispose(); hv_RowEnd.Dispose(); hv_ColEnd.Dispose(); hv_RowLine.Dispose(); hv_ColLine.Dispose();
                        //if ((int)(new HTuple(hv_Orient.TupleEqual(1))) != 0)
                        //{
                        rake_edge(ho_DupImage, hv_r, hv_c + hv_H_Dist, (hv_Phi), 130, hv_V_Length * hv_Rate_H,
                       1, 1, 45, hv_Transition, "first", "FALSE", "FALSE", "TRUE",
                       0, 0, out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd,
                       out hv_RowLine, out hv_ColLine);
                        //}else
                        //{
                        //    rake_edge(ho_DupImage, hv_r, hv_c + hv_H_Dist, (hv_Phi.D + 0.26), 130, hv_V_Length * hv_Rate_H,
                        //   1, 1, 45, hv_Transition, "first", "FALSE", "FALSE", "TRUE",
                        //   0, 0, out hv_RowBegin, out hv_ColBegin, out hv_RowEnd, out hv_ColEnd,
                        //   out hv_RowLine, out hv_ColLine);
                        //}


                    }
                    //剔除极片掉料影响-----20240111*
                    hv_RowLines.Dispose();
                    hv_RowLines = new HTuple();
                    hv_ColLines.Dispose();
                    hv_ColLines = new HTuple();
                    //去掉最大最小值*
                    hv_Min.Dispose();
                    HOperatorSet.TupleMin(hv_ColLine, out hv_Min);
                    hv_Max.Dispose();
                    HOperatorSet.TupleMax(hv_ColLine, out hv_Max);
                    hv_Indices_Min.Dispose();
                    HOperatorSet.TupleFind(hv_ColLine, hv_Min, out hv_Indices_Min);
                    hv_Indices_Max.Dispose();
                    HOperatorSet.TupleFind(hv_ColLine, hv_Max, out hv_Indices_Max);
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.TupleRemove(hv_RowLine, hv_Indices_Min, out ExpTmpOutVar_0);
                        hv_RowLine.Dispose();
                        hv_RowLine = ExpTmpOutVar_0;
                    }
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.TupleRemove(hv_RowLine, hv_Indices_Max, out ExpTmpOutVar_0);
                        hv_RowLine.Dispose();
                        hv_RowLine = ExpTmpOutVar_0;
                    }
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.TupleRemove(hv_ColLine, hv_Indices_Min, out ExpTmpOutVar_0);
                        hv_ColLine.Dispose();
                        hv_ColLine = ExpTmpOutVar_0;
                    }
                    {
                        HTuple ExpTmpOutVar_0;
                        HOperatorSet.TupleRemove(hv_ColLine, hv_Indices_Max, out ExpTmpOutVar_0);
                        hv_ColLine.Dispose();
                        hv_ColLine = ExpTmpOutVar_0;
                    }
                    hv_Length.Dispose();
                    HOperatorSet.TupleLength(hv_ColLine, out hv_Length);
                    //取中位数*
                    hv_Median.Dispose();
                    HOperatorSet.TupleMedian(hv_ColLine, out hv_Median);
                    hv_Indices_M.Dispose();
                    HOperatorSet.TupleFind(hv_ColLine, hv_Median, out hv_Indices_M);
                    HTuple end_val106 = hv_Indices_M;
                    HTuple step_val106 = 1;
                    for (hv_i = 0; hv_i.Continue(end_val106, step_val106); hv_i = hv_i.TupleAdd(step_val106))
                    {
                        if ((int)(new HTuple((((((hv_ColLine.TupleSelect(hv_i)) - (hv_ColLine.TupleSelect(
                            hv_i + 1)))).TupleAbs())).TupleLess(3))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                HTuple ExpTmpOutVar_0;
                                HOperatorSet.TupleConcat(hv_RowLine.TupleSelect(hv_i), hv_RowLines, out ExpTmpOutVar_0);
                                hv_RowLines.Dispose();
                                hv_RowLines = ExpTmpOutVar_0;
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                HTuple ExpTmpOutVar_0;
                                HOperatorSet.TupleConcat(hv_ColLine.TupleSelect(hv_i), hv_ColLines, out ExpTmpOutVar_0);
                                hv_ColLines.Dispose();
                                hv_ColLines = ExpTmpOutVar_0;
                            }
                        }
                    }
                    HTuple end_val112 = hv_Length - 2;
                    HTuple step_val112 = 1;
                    for (hv_i = hv_Indices_M; hv_i.Continue(end_val112, step_val112); hv_i = hv_i.TupleAdd(step_val112))
                    {
                        if ((int)(new HTuple((((((hv_ColLine.TupleSelect(hv_i)) - (hv_ColLine.TupleSelect(
                            hv_i + 1)))).TupleAbs())).TupleLess(3))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                HTuple ExpTmpOutVar_0;
                                HOperatorSet.TupleConcat(hv_RowLine.TupleSelect(hv_i), hv_RowLines, out ExpTmpOutVar_0);
                                hv_RowLines.Dispose();
                                hv_RowLines = ExpTmpOutVar_0;
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                HTuple ExpTmpOutVar_0;
                                HOperatorSet.TupleConcat(hv_ColLine.TupleSelect(hv_i), hv_ColLines, out ExpTmpOutVar_0);
                                hv_ColLines.Dispose();
                                hv_ColLines = ExpTmpOutVar_0;
                            }
                        }
                    }
                    //剔除极片掉料影响-----20240111*

                    //根据一系列点拟合圆*
                    ho_ContoursSplit.Dispose();
                    HOperatorSet.GenContourPolygonXld(out ho_ContoursSplit, hv_RowLines, hv_ColLines);
                    //HOperatorSet.CopyObj(ho_ContoursSplit, out ho_Line, 1, 1);
                    //ho_Line = ho_ContoursSplit;//将找到的圆弧边传出去，用于缩放时显示
                    HOperatorSet.DispObj(ho_ContoursSplit, hv_WindowHandle);
                    hv_Min.Dispose();
                    HOperatorSet.TupleMin(hv_ColLine, out hv_Min);
                    hv_Row.Dispose(); hv_Column.Dispose(); hv_Radius.Dispose(); hv_StartPhi.Dispose(); hv_EndPhi.Dispose(); hv_PointOrder.Dispose();
                    HOperatorSet.FitCircleContourXld(ho_ContoursSplit, "algebraic", -1, 0, 0,
                        3, 2, out hv_Row, out hv_Column, out hv_Radius, out hv_StartPhi, out hv_EndPhi,
                        out hv_PointOrder);
                    ho_ContCircle_Cor.Dispose();
                    HOperatorSet.GenCircleContourXld(out ho_ContCircle_Cor, hv_Row, hv_Column,
                        hv_Radius, -3.14, 3.14, "positive", 1);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Contour.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowBegin1_U.TupleConcat(
                            hv_RowEnd1_U), hv_ColBegin1_U.TupleConcat(hv_ColEnd1_U));
                    }

                    //判断圆弧和横边是否有交点*
                    hv_Row2.Dispose(); hv_Column2.Dispose(); hv_IsOverlapping.Dispose();
                    HOperatorSet.IntersectionLineContourXld(ho_ContCircle_Cor, hv_RowBegin1_U,
                        hv_ColBegin1_U, hv_RowEnd1_U, hv_ColEnd1_U, out hv_Row2, out hv_Column2,
                        out hv_IsOverlapping);
                    if ((int)(new HTuple((new HTuple(hv_Row2.TupleLength())).TupleLess(2))) != 0)
                    {
                        for (hv_i = 0; (int)hv_i <= 100; hv_i = (int)hv_i + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                ho_ContCircle.Dispose();
                                HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column,
                                    hv_Radius + hv_i, -3.14, 3.14, "positive", 1);
                            }
                            hv_Row2.Dispose(); hv_Column2.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_ContCircle, hv_RowBegin1_U,
                                hv_ColBegin1_U, hv_RowEnd1_U, hv_ColEnd1_U, out hv_Row2, out hv_Column2,
                                out hv_IsOverlapping);
                            if ((int)(new HTuple((new HTuple(hv_Row2.TupleLength())).TupleGreater(
                                1))) != 0)
                            {
                                hv_Row_QD.Dispose();
                                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                                {
                                    hv_Row_QD = ((hv_Row2.TupleSelect(
                                        0)) + (hv_Row2.TupleSelect(1))) * 0.5;
                                }
                                hv_Col_QD.Dispose();
                                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                                {
                                    hv_Col_QD = ((hv_Column2.TupleSelect(
                                        0)) + (hv_Column2.TupleSelect(1))) * 0.5;
                                }
                                break;
                            }
                            else
                            {
                                hv_Row_QD.Dispose();
                                hv_Row_QD = -1;
                                hv_Col_QD.Dispose();
                                hv_Col_QD = -1;
                            }
                        }
                    }
                    else
                    {
                        hv_Row2.Dispose(); hv_Column2.Dispose(); hv_IsOverlapping.Dispose();
                        HOperatorSet.IntersectionLineContourXld(ho_ContCircle_Cor, hv_RowBegin1_U,
                            hv_ColBegin1_U, hv_RowEnd1_U, hv_ColEnd1_U, out hv_Row2, out hv_Column2,
                            out hv_IsOverlapping);
                        hv_Row_QD.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_Row_QD = ((hv_Row2.TupleSelect(
                                0)) + (hv_Row2.TupleSelect(1))) * 0.5;
                        }
                        hv_Col_QD.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_Col_QD = ((hv_Column2.TupleSelect(
                                0)) + (hv_Column2.TupleSelect(1))) * 0.5;
                        }
                    }

                }
                else
                {
                    hv_Row_QD.Dispose();
                    hv_Row_QD = -1;
                    hv_Col_QD.Dispose();
                    hv_Col_QD = -1;
                }



                HOperatorSet.DispCross(hv_WindowHandle, hv_Row_QD, hv_Col_QD, 45, 0);
                hv_Lines[5] = hv_Row_QD; hv_Lines[6] = hv_Col_QD;

                ho_Rectangle2.Dispose();
                ho_Contour_U.Dispose();
                ho_Contour_L.Dispose();
                ho_Contour_YH.Dispose();
                ho_Region_YH.Dispose();
                ho_Rectangle_YH.Dispose();
                ho_Rectangle.Dispose();
                ho_ContoursSplit.Dispose();
                ho_Contour.Dispose();
                ho_ContCircle.Dispose();

                hv_Row1.Dispose();
                hv_Col1.Dispose();
                hv_Phi1.Dispose();
                hv_Length11.Dispose();
                hv_Length21.Dispose();
                hv_Step.Dispose();
                hv_Sigma.Dispose();
                hv_Threshold.Dispose();
                hv_Transition.Dispose();
                hv_Orient.Dispose();
                hv_V_Dist.Dispose();
                hv_H_Dist.Dispose();
                hv_Rate_H.Dispose();
                hv_Width.Dispose();
                hv_Height.Dispose();
                hv_RowBegin1_U.Dispose();
                hv_ColBegin1_U.Dispose();
                hv_RowEnd1_U.Dispose();
                hv_ColEnd1_U.Dispose();
                hv_Row_Line.Dispose();
                hv_Col_Line.Dispose();
                hv_Row2.Dispose();
                hv_Col2.Dispose();
                hv_Phi2.Dispose();
                hv_Angle.Dispose();
                hv_Phi.Dispose();
                hv_c1.Dispose();
                hv_r1.Dispose();
                hv_c2.Dispose();
                hv_r2.Dispose();
                hv_c.Dispose();
                hv_r.Dispose();
                hv_Mid_Row.Dispose();
                hv_Mid_Col.Dispose();
                hv_H_Length.Dispose();
                hv_V_Length.Dispose();
                hv_RowBegin.Dispose();
                hv_ColBegin.Dispose();
                hv_RowEnd.Dispose();
                hv_ColEnd.Dispose();
                hv_RowLine.Dispose();
                hv_ColLine.Dispose();
                hv_Min.Dispose();
                hv_Row.Dispose();
                hv_Column.Dispose();
                hv_Radius.Dispose();
                hv_StartPhi.Dispose();
                hv_EndPhi.Dispose();
                hv_PointOrder.Dispose();
                hv_Column2.Dispose();
                hv_IsOverlapping.Dispose();
                hv_i.Dispose();
                hv_IsParallel.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_Rectangle2.Dispose();
                ho_Contour_U.Dispose();
                ho_Contour_L.Dispose();
                ho_Contour_YH.Dispose();
                ho_Region_YH.Dispose();
                ho_Rectangle_YH.Dispose();
                ho_Rectangle.Dispose();
                ho_ContoursSplit.Dispose();
                ho_Contour.Dispose();
                ho_ContCircle.Dispose();

                hv_Row1.Dispose();
                hv_Col1.Dispose();
                hv_Phi1.Dispose();
                hv_Length11.Dispose();
                hv_Length21.Dispose();
                hv_Step.Dispose();
                hv_Sigma.Dispose();
                hv_Threshold.Dispose();
                hv_Transition.Dispose();
                hv_Orient.Dispose();
                hv_V_Dist.Dispose();
                hv_H_Dist.Dispose();
                hv_Rate_H.Dispose();
                hv_Width.Dispose();
                hv_Height.Dispose();
                hv_RowBegin1_U.Dispose();
                hv_ColBegin1_U.Dispose();
                hv_RowEnd1_U.Dispose();
                hv_ColEnd1_U.Dispose();
                hv_Row_Line.Dispose();
                hv_Col_Line.Dispose();
                hv_Row2.Dispose();
                hv_Col2.Dispose();
                hv_Phi2.Dispose();
                hv_Angle.Dispose();
                hv_Phi.Dispose();
                hv_c1.Dispose();
                hv_r1.Dispose();
                hv_c2.Dispose();
                hv_r2.Dispose();
                hv_c.Dispose();
                hv_r.Dispose();
                hv_Mid_Row.Dispose();
                hv_Mid_Col.Dispose();
                hv_H_Length.Dispose();
                hv_V_Length.Dispose();
                hv_RowBegin.Dispose();
                hv_ColBegin.Dispose();
                hv_RowEnd.Dispose();
                hv_ColEnd.Dispose();
                hv_RowLine.Dispose();
                hv_ColLine.Dispose();
                hv_Min.Dispose();
                hv_Row.Dispose();
                hv_Column.Dispose();
                hv_Radius.Dispose();
                hv_StartPhi.Dispose();
                hv_EndPhi.Dispose();
                hv_PointOrder.Dispose();
                hv_Column2.Dispose();
                hv_IsOverlapping.Dispose();
                hv_i.Dispose();
                hv_IsParallel.Dispose();
                //Tool.LogForm("极耳圆弧计算切点失败" + HDevExpDefaultException.ToString());
            }
        }



        #region V角圆弧检测
        public static void Detect_LD_V(HObject ho_Image, HWindow hw, HTuple hv_Parms, HTuple hv_RowBegin_H,
     HTuple hv_ColBegin_H, HTuple hv_RowEnd_H, HTuple hv_ColEnd_H, HTuple hv_RowBegin_V,
     HTuple hv_ColBegin_V, HTuple hv_RowEnd_V, HTuple hv_ColEnd_V, out HTuple hv_VR,
     out HTuple hv_VC, out HTuple hv_HR, out HTuple hv_HC)
        {




            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_DupImage, ho_Circle = null, ho_Contours = null;
            HObject ho_ImageReduced1 = null, ho_Region = null, ho_RegionOpening = null;
            HObject ho_ConnectedRegions = null, ho_ObjectSelected = null;
            HObject ho_Contour = null, ho_RegionFillUp = null, ho_Rectangle1 = null;
            HObject ho_Contour1 = null, ho_RegionDifference = null, ho_ConnectedRegions1 = null;
            HObject ho_Rectangle2 = null, ho_Contours1 = null, ho_ContourV = null;
            HObject ho_ContourH = null, ho_ContourV1 = null, ho_Circle1 = null;
            HObject ho_CircleV = null, ho_ContourH1 = null, ho_CircleH = null;

            // Local control variables 

            HTuple hv_Pixel = new HTuple(), hv_JD_Gray = new HTuple();
            HTuple hv_JD_Dist = new HTuple(), hv_Radius_LD = new HTuple();
            HTuple hv_VH_R = new HTuple(), hv_VH_C = new HTuple();
            HTuple hv_Ra = new HTuple(), hv_Dist_H = new HTuple();
            HTuple hv_Dist_W = new HTuple(), hv_RowBegin_H0 = new HTuple();
            HTuple hv_ColBegin_H0 = new HTuple(), hv_RowEnd_H0 = new HTuple();
            HTuple hv_ColEnd_H0 = new HTuple(), hv_RowBegin_V0 = new HTuple();
            HTuple hv_ColBegin_V0 = new HTuple(), hv_RowEnd_V0 = new HTuple();
            HTuple hv_ColEnd_V0 = new HTuple(), hv_AngleH = new HTuple();
            HTuple hv_AngleV = new HTuple(), hv_Angle = new HTuple();
            HTuple hv_Angle_Sub = new HTuple(), hv_Width = new HTuple();
            HTuple hv_Height = new HTuple(), hv_K_H = new HTuple();
            HTuple hv_K_BH = new HTuple(), hv_K_V = new HTuple(), hv_K_BV = new HTuple();
            HTuple hv_Row = new HTuple(), hv_Column = new HTuple();
            HTuple hv_IsParallel = new HTuple(), hv_UsedThreshold = new HTuple();
            HTuple hv_Area = new HTuple(), hv_Max = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Mean = new HTuple(), hv_Deviation = new HTuple();
            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
            HTuple hv_Row21 = new HTuple(), hv_Column21 = new HTuple();
            HTuple hv_Col = new HTuple(), hv_Phi = new HTuple(), hv_Length2 = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_a = new HTuple();
            HTuple hv_Rows = new HTuple(), hv_Cols = new HTuple();
            HTuple hv_j = new HTuple(), hv_R = new HTuple(), hv_C = new HTuple();
            HTuple hv_IsOverlapping = new HTuple(), hv_Dists = new HTuple();
            HTuple hv_i = new HTuple(), hv_R1 = new HTuple(), hv_C1 = new HTuple();
            HTuple hv_Grayval = new HTuple(), hv_Dist = new HTuple();
            HTuple hv_Min = new HTuple(), hv_Grayval0 = new HTuple();
            HTuple hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H);
            HTuple hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V);
            HTuple hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H);
            HTuple hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V);
            HTuple hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H);
            HTuple hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V);
            HTuple hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H);
            HTuple hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V);

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_DupImage);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Contour1);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out ho_Contours1);
            HOperatorSet.GenEmptyObj(out ho_ContourV);
            HOperatorSet.GenEmptyObj(out ho_ContourH);
            HOperatorSet.GenEmptyObj(out ho_ContourV1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_CircleV);
            HOperatorSet.GenEmptyObj(out ho_ContourH1);
            HOperatorSet.GenEmptyObj(out ho_CircleH);
            hv_VR = new HTuple();
            hv_VC = new HTuple();
            hv_HR = new HTuple();
            hv_HC = new HTuple();


            //像素比*
            hv_Pixel.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Pixel = hv_Parms.TupleSelect(
                    0);
            }
            //角点灰度值*
            hv_JD_Gray.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Gray = hv_Parms.TupleSelect(
                    1);
            }
            //角点距离轮廓距离*
            hv_JD_Dist.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Dist = hv_Parms.TupleSelect(
                    2);
            }
            //左下角圆半径*
            hv_Radius_LD.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Radius_LD = hv_Parms.TupleSelect(
                    3);
            }

            //初始化*
            hv_VH_R.Dispose();
            hv_VH_R = 0;
            hv_VH_C.Dispose();
            hv_VH_C = 0;
            hv_Ra.Dispose();
            hv_Ra = 0;

            hv_VR.Dispose();
            hv_VR = 0;
            hv_VC.Dispose();
            hv_VC = 0;
            hv_HR.Dispose();
            hv_HR = 0;
            hv_HC.Dispose();
            hv_HC = 0;
            hv_Dist_H.Dispose();
            hv_Dist_H = 0;
            hv_Dist_W.Dispose();
            hv_Dist_W = 0;
            //横边斜率*
            hv_RowBegin_H0.Dispose();
            hv_RowBegin_H0 = new HTuple(hv_RowBegin_H_COPY_INP_TMP);
            hv_ColBegin_H0.Dispose();
            hv_ColBegin_H0 = new HTuple(hv_ColBegin_H_COPY_INP_TMP);
            hv_RowEnd_H0.Dispose();
            hv_RowEnd_H0 = new HTuple(hv_RowEnd_H_COPY_INP_TMP);
            hv_ColEnd_H0.Dispose();
            hv_ColEnd_H0 = new HTuple(hv_ColEnd_H_COPY_INP_TMP);

            hv_RowBegin_V0.Dispose();
            hv_RowBegin_V0 = new HTuple(hv_RowBegin_V_COPY_INP_TMP);
            hv_ColBegin_V0.Dispose();
            hv_ColBegin_V0 = new HTuple(hv_ColBegin_V_COPY_INP_TMP);
            hv_RowEnd_V0.Dispose();
            hv_RowEnd_V0 = new HTuple(hv_RowEnd_V_COPY_INP_TMP);
            hv_ColEnd_V0.Dispose();
            hv_ColEnd_V0 = new HTuple(hv_ColEnd_V_COPY_INP_TMP);
            ho_DupImage.Dispose();
            HOperatorSet.CopyImage(ho_Image, out ho_DupImage);
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs());
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (((hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs()))).TupleAbs();
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }
            hv_Width.Dispose(); hv_Height.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);

            try
            {


                if ((int)((new HTuple((new HTuple((new HTuple((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(
                    0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(
                    new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(
                    0))))).TupleAnd(new HTuple(hv_Angle_Sub.TupleLess(0.2)))) != 0)
                {
                    hv_K_H.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_K_H = (hv_RowEnd_H_COPY_INP_TMP - hv_RowBegin_H_COPY_INP_TMP) / ((hv_ColEnd_H_COPY_INP_TMP - hv_ColBegin_H_COPY_INP_TMP) + 0.0001);
                    }
                    hv_K_BH.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_K_BH = hv_RowEnd_H_COPY_INP_TMP - (hv_K_H * hv_ColEnd_H_COPY_INP_TMP);
                    }
                    hv_ColEnd_H_COPY_INP_TMP.Dispose();
                    hv_ColEnd_H_COPY_INP_TMP = 0;
                    hv_RowEnd_H_COPY_INP_TMP.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowEnd_H_COPY_INP_TMP = (hv_K_H * hv_ColBegin_H_COPY_INP_TMP) + hv_K_BH;
                    }
                    //竖边斜率*
                    hv_K_V.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_K_V = (hv_RowEnd_V_COPY_INP_TMP - hv_RowBegin_V_COPY_INP_TMP) / ((hv_ColEnd_V_COPY_INP_TMP - hv_ColBegin_V_COPY_INP_TMP) + 0.0001);
                    }
                    hv_K_BV.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_K_BV = hv_RowEnd_V_COPY_INP_TMP - (hv_K_V * hv_ColEnd_V_COPY_INP_TMP);
                    }
                    hv_RowBegin_V_COPY_INP_TMP.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_RowBegin_V_COPY_INP_TMP = hv_Height - 1;
                    }
                    hv_ColBegin_V_COPY_INP_TMP.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_ColBegin_V_COPY_INP_TMP = (hv_RowBegin_V_COPY_INP_TMP - hv_K_BV) / (hv_K_V + 0.0001);
                    }
                    //横边和竖边交点*
                    hv_Row.Dispose(); hv_Column.Dispose(); hv_IsParallel.Dispose();
                    HOperatorSet.IntersectionLl(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                        hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, hv_RowBegin_V_COPY_INP_TMP,
                        hv_ColBegin_V_COPY_INP_TMP, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP,
                        out hv_Row, out hv_Column, out hv_IsParallel);
                    //生成圆*
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius_LD / hv_Pixel);
                    HOperatorSet.DispObj(ho_Circle, hw);

                    ho_Contours.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Circle, out ho_Contours, "border");
                    ho_ImageReduced1.Dispose();
                    HOperatorSet.ReduceDomain(ho_Image, ho_Circle, out ho_ImageReduced1);
                    ho_Region.Dispose(); hv_UsedThreshold.Dispose();
                    HOperatorSet.BinaryThreshold(ho_ImageReduced1, out ho_Region, "max_separability",
                        "dark", out hv_UsedThreshold);
                    ho_RegionOpening.Dispose();
                    HOperatorSet.OpeningRectangle1(ho_Region, out ho_RegionOpening, 10, 10);
                    ho_ConnectedRegions.Dispose();
                    HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
                    hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                    HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row, out hv_Column);
                    hv_Max.Dispose();
                    HOperatorSet.TupleMax(hv_Area, out hv_Max);
                    hv_Index.Dispose();
                    HOperatorSet.TupleFindFirst(hv_Area, hv_Max, out hv_Index);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_ConnectedRegions, out ho_ObjectSelected, hv_Index + 1);
                    }
                    ho_Contour.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_ObjectSelected, out ho_Contour, "border");
                    hv_Mean.Dispose(); hv_Deviation.Dispose();
                    HOperatorSet.Intensity(ho_ObjectSelected, ho_DupImage, out hv_Mean, out hv_Deviation);
                    ho_RegionFillUp.Dispose();
                    HOperatorSet.FillUp(ho_ObjectSelected, out ho_RegionFillUp);
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_RegionFillUp, hv_Mean, "fill");
                    //外接矩形*
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1Xld(ho_Contour, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle1.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    ho_Contour1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle1, out ho_Contour1, "border");
                    //白色区域防止竖边有干扰。拟合圆不准确*
                    ho_RegionDifference.Dispose();
                    HOperatorSet.Difference(ho_Rectangle1, ho_RegionFillUp, out ho_RegionDifference
                        );
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_RegionDifference, out ExpTmpOutVar_0, 9,
                            9);
                        ho_RegionDifference.Dispose();
                        ho_RegionDifference = ExpTmpOutVar_0;
                    }
                    ho_ConnectedRegions1.Dispose();
                    HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1);
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected, 2);
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_ObjectSelected, out ExpTmpOutVar_0, 3, 3);
                        ho_ObjectSelected.Dispose();
                        ho_ObjectSelected = ExpTmpOutVar_0;
                    }
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_ObjectSelected, 255, "fill");
                    hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row11, out hv_Column11,
                        out hv_Row21, out hv_Column21);
                    ho_Rectangle2.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle2, hv_Row11, hv_Column11, hv_Row21,
                        hv_Column21);
                    ho_Contours1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle2, out ho_Contours1, "border");

                    //竖边找边*
                    hv_Row.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Row = (hv_Row1 + hv_Row11) * 0.5;
                    }
                    hv_Col.Dispose();
                    hv_Col = new HTuple(hv_Column1);
                    hv_Phi.Dispose();
                    hv_Phi = 3.14;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Row11 - hv_Row1) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 50;
                    hv_RowBegin_V_COPY_INP_TMP.Dispose(); hv_ColBegin_V_COPY_INP_TMP.Dispose(); hv_RowEnd_V_COPY_INP_TMP.Dispose(); hv_ColEnd_V_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_V_COPY_INP_TMP,
                        out hv_ColBegin_V_COPY_INP_TMP, out hv_RowEnd_V_COPY_INP_TMP, out hv_ColEnd_V_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourV.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourV, hv_RowEnd_V_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_V_COPY_INP_TMP), hv_ColEnd_V_COPY_INP_TMP.TupleConcat(hv_ColBegin_V_COPY_INP_TMP));
                    }
                    //横边找边*
                    hv_Row.Dispose();
                    hv_Row = new HTuple(hv_Row2);
                    hv_Col.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Col = (hv_Column2 + hv_Column21) * 0.5;
                    }
                    hv_Phi.Dispose();
                    hv_Phi = -1.57;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Column2 - hv_Column21) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 30;
                    hv_RowBegin_H_COPY_INP_TMP.Dispose(); hv_ColBegin_H_COPY_INP_TMP.Dispose(); hv_RowEnd_H_COPY_INP_TMP.Dispose(); hv_ColEnd_H_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_H_COPY_INP_TMP,
                        out hv_ColBegin_H_COPY_INP_TMP, out hv_RowEnd_H_COPY_INP_TMP, out hv_ColEnd_H_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourH.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourH, hv_RowEnd_H_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_H_COPY_INP_TMP), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(hv_ColBegin_H_COPY_INP_TMP));
                    }

                    if ((int)((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_H_COPY_INP_TMP.Dispose();
                        hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H0);
                        hv_ColBegin_H_COPY_INP_TMP.Dispose();
                        hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H0);
                        hv_RowEnd_H_COPY_INP_TMP.Dispose();
                        hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H0);
                        hv_ColEnd_H_COPY_INP_TMP.Dispose();
                        hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H0);
                    }

                    if ((int)((new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_V_COPY_INP_TMP.Dispose();
                        hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V0);
                        hv_ColBegin_V_COPY_INP_TMP.Dispose();
                        hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V0);
                        hv_RowEnd_V_COPY_INP_TMP.Dispose();
                        hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V0);
                        hv_ColEnd_V_COPY_INP_TMP.Dispose();
                        hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V0);
                    }
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    //竖边向左平移*
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourV1.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourV1, hv_RowBegin_V_COPY_INP_TMP.TupleConcat(
                                hv_RowEnd_V_COPY_INP_TMP), ((hv_ColBegin_V_COPY_INP_TMP + hv_j)).TupleConcat(
                                hv_ColEnd_V_COPY_INP_TMP + hv_j));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowEnd_V_COPY_INP_TMP,
                                hv_ColEnd_V_COPY_INP_TMP + hv_j, hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP + hv_j,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }

                    }


                    //挑选Rows最大值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_VR.Dispose();
                        HOperatorSet.TupleMax(hv_Rows, out hv_VR);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Rows, hv_VR, out hv_Index);
                        hv_VC.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_VC = hv_Cols.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_VR = new HTuple(hv_VR);
                            hv_VR.Dispose();
                            hv_VR = ExpTmpLocalVar_VR;
                        }
                    }
                    else
                    {
                        hv_VC.Dispose();
                        hv_VC = 0;
                        hv_VR.Dispose();
                        hv_VR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_VR, hv_VC, hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                            hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_VR.Dispose();
                        hv_VR = ExpTmpOutVar_0;
                        hv_VC.Dispose();
                        hv_VC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 0; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_V.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_V = (hv_RowEnd_V_COPY_INP_TMP - hv_RowBegin_V_COPY_INP_TMP) / ((hv_ColEnd_V_COPY_INP_TMP - hv_ColBegin_V_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BV.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BV = hv_RowEnd_V_COPY_INP_TMP - (hv_K_V * hv_ColEnd_V_COPY_INP_TMP);
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = hv_VR - hv_i;
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = (((hv_R1 - hv_K_BV) / (hv_K_V + 0.00001))).TupleCeil()
                                ;
                        }
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        ho_Circle1.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle1, hv_R1, hv_C1, 0.5);

                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_VC.Dispose();
                            hv_VC = new HTuple(hv_C1);
                            hv_VR.Dispose();
                            hv_VR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleV.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleV, hv_VR, hv_VC, 0.5);

                    //斜边和长横边的交点*
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    //横边向上平移*
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourH1.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourH1, ((hv_RowEnd_H_COPY_INP_TMP - hv_j)).TupleConcat(
                                hv_RowBegin_H_COPY_INP_TMP - hv_j), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(
                                hv_ColBegin_H_COPY_INP_TMP));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_H_COPY_INP_TMP - hv_j,
                                hv_ColBegin_H_COPY_INP_TMP, hv_RowEnd_H_COPY_INP_TMP - hv_j, hv_ColEnd_H_COPY_INP_TMP,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }

                    }


                    //挑选Col最大值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_HC.Dispose();
                        HOperatorSet.TupleMin(hv_Cols, out hv_HC);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Cols, hv_HC, out hv_Index);
                        hv_HR.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_HR = hv_Rows.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_HC = new HTuple(hv_HC);
                            hv_HC.Dispose();
                            hv_HC = ExpTmpLocalVar_HC;
                        }
                    }
                    else
                    {
                        hv_HC.Dispose();
                        hv_HC = 0;
                        hv_HR.Dispose();
                        hv_HR = 0;
                    }
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourH.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourH, hv_RowEnd_H_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_H_COPY_INP_TMP), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(hv_ColBegin_H_COPY_INP_TMP));
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_HR, hv_HC, hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                            hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_HR.Dispose();
                        hv_HR = ExpTmpOutVar_0;
                        hv_HC.Dispose();
                        hv_HC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 1; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_H.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_H = (hv_RowEnd_H_COPY_INP_TMP - hv_RowBegin_H_COPY_INP_TMP) / ((hv_ColEnd_H_COPY_INP_TMP - hv_ColBegin_H_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BH.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BH = hv_RowEnd_H_COPY_INP_TMP - (hv_K_H * hv_ColEnd_H_COPY_INP_TMP);
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = hv_HC + hv_i;
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = (((hv_C1 * hv_K_H) + hv_K_BH)).TupleFloor()
                                ;
                        }
                        hv_C.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C = hv_HC + hv_i;
                        }
                        hv_R.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R = (hv_C1 * hv_K_H) + hv_K_BH;
                        }
                        if ((int)((new HTuple(((hv_R - (hv_R.TupleRound()))).TupleLess(0))).TupleAnd(
                            new HTuple(((((hv_R - (hv_R.TupleRound()))).TupleAbs())).TupleGreater(0.25)))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleRound()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }
                        }
                        else
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleFloor()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }

                        }
                        hv_Grayval0.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R, hv_C, out hv_Grayval0);
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        ho_Circle1.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle1, hv_R1, hv_C1, 0.5);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_HC.Dispose();
                            hv_HC = new HTuple(hv_C1);
                            hv_HR.Dispose();
                            hv_HR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleH.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleH, hv_HR, hv_HC, 0.5);

                }

            }
            catch (Exception)
            {

            }
            ho_DupImage.Dispose();
            ho_Circle.Dispose();
            ho_Contours.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Region.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_ObjectSelected.Dispose();
            ho_Contour.Dispose();
            ho_RegionFillUp.Dispose();
            ho_Rectangle1.Dispose();
            ho_Contour1.Dispose();
            ho_RegionDifference.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_Rectangle2.Dispose();
            ho_Contours1.Dispose();
            ho_ContourV.Dispose();
            ho_ContourH.Dispose();
            ho_ContourV1.Dispose();
            ho_Circle1.Dispose();
            ho_CircleV.Dispose();
            ho_ContourH1.Dispose();
            ho_CircleH.Dispose();

            hv_ColBegin_H_COPY_INP_TMP.Dispose();
            hv_ColBegin_V_COPY_INP_TMP.Dispose();
            hv_ColEnd_H_COPY_INP_TMP.Dispose();
            hv_ColEnd_V_COPY_INP_TMP.Dispose();
            hv_RowBegin_H_COPY_INP_TMP.Dispose();
            hv_RowBegin_V_COPY_INP_TMP.Dispose();
            hv_RowEnd_H_COPY_INP_TMP.Dispose();
            hv_RowEnd_V_COPY_INP_TMP.Dispose();
            hv_Pixel.Dispose();
            hv_JD_Gray.Dispose();
            hv_JD_Dist.Dispose();
            hv_Radius_LD.Dispose();
            hv_VH_R.Dispose();
            hv_VH_C.Dispose();
            hv_Ra.Dispose();
            hv_Dist_H.Dispose();
            hv_Dist_W.Dispose();
            hv_RowBegin_H0.Dispose();
            hv_ColBegin_H0.Dispose();
            hv_RowEnd_H0.Dispose();
            hv_ColEnd_H0.Dispose();
            hv_RowBegin_V0.Dispose();
            hv_ColBegin_V0.Dispose();
            hv_RowEnd_V0.Dispose();
            hv_ColEnd_V0.Dispose();
            hv_AngleH.Dispose();
            hv_AngleV.Dispose();
            hv_Angle.Dispose();
            hv_Angle_Sub.Dispose();
            hv_Width.Dispose();
            hv_Height.Dispose();
            hv_K_H.Dispose();
            hv_K_BH.Dispose();
            hv_K_V.Dispose();
            hv_K_BV.Dispose();
            hv_Row.Dispose();
            hv_Column.Dispose();
            hv_IsParallel.Dispose();
            hv_UsedThreshold.Dispose();
            hv_Area.Dispose();
            hv_Max.Dispose();
            hv_Index.Dispose();
            hv_Mean.Dispose();
            hv_Deviation.Dispose();
            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Row11.Dispose();
            hv_Column11.Dispose();
            hv_Row21.Dispose();
            hv_Column21.Dispose();
            hv_Col.Dispose();
            hv_Phi.Dispose();
            hv_Length2.Dispose();
            hv_Length1.Dispose();
            hv_a.Dispose();
            hv_Rows.Dispose();
            hv_Cols.Dispose();
            hv_j.Dispose();
            hv_R.Dispose();
            hv_C.Dispose();
            hv_IsOverlapping.Dispose();
            hv_Dists.Dispose();
            hv_i.Dispose();
            hv_R1.Dispose();
            hv_C1.Dispose();
            hv_Grayval.Dispose();
            hv_Dist.Dispose();
            hv_Min.Dispose();
            hv_Grayval0.Dispose();

            return;
        }

        public static void Detect_LU_V(HObject ho_Image, HWindow hw, HTuple hv_Parms, HTuple hv_RowBegin_H,
            HTuple hv_ColBegin_H, HTuple hv_RowEnd_H, HTuple hv_ColEnd_H, HTuple hv_RowBegin_V,
            HTuple hv_ColBegin_V, HTuple hv_RowEnd_V, HTuple hv_ColEnd_V, out HTuple hv_VR,
            out HTuple hv_VC, out HTuple hv_HR, out HTuple hv_HC)
        {




            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_DupImage, ho_Circle = null, ho_Contours = null;
            HObject ho_ImageReduced1 = null, ho_Region = null, ho_RegionOpening = null;
            HObject ho_ConnectedRegions = null, ho_ObjectSelected = null;
            HObject ho_Contour = null, ho_RegionFillUp = null, ho_Rectangle1 = null;
            HObject ho_Contour1 = null, ho_RegionDifference = null, ho_ConnectedRegions1 = null;
            HObject ho_Rectangle2 = null, ho_Contours1 = null, ho_ContourV = null;
            HObject ho_ContourH = null, ho_CircleV = null, ho_ContourH1 = null;
            HObject ho_Circle1 = null, ho_CircleH = null;

            // Local control variables 

            HTuple hv_Pixel = new HTuple(), hv_JD_Gray = new HTuple();
            HTuple hv_JD_Dist = new HTuple(), hv_Radius_LU = new HTuple();
            HTuple hv_VH_R = new HTuple(), hv_VH_C = new HTuple();
            HTuple hv_Ra = new HTuple(), hv_Dist_H = new HTuple();
            HTuple hv_Dist_W = new HTuple(), hv_RowBegin_H0 = new HTuple();
            HTuple hv_ColBegin_H0 = new HTuple(), hv_RowEnd_H0 = new HTuple();
            HTuple hv_ColEnd_H0 = new HTuple(), hv_RowBegin_V0 = new HTuple();
            HTuple hv_ColBegin_V0 = new HTuple(), hv_RowEnd_V0 = new HTuple();
            HTuple hv_ColEnd_V0 = new HTuple(), hv_AngleH = new HTuple();
            HTuple hv_AngleV = new HTuple(), hv_Angle = new HTuple();
            HTuple hv_Angle_Sub = new HTuple(), hv_Width = new HTuple();
            HTuple hv_Height = new HTuple(), hv_Row = new HTuple();
            HTuple hv_Column = new HTuple(), hv_IsParallel = new HTuple();
            HTuple hv_UsedThreshold = new HTuple(), hv_Area = new HTuple();
            HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Mean = new HTuple(), hv_Deviation = new HTuple();
            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
            HTuple hv_Row21 = new HTuple(), hv_Column21 = new HTuple();
            HTuple hv_Col = new HTuple(), hv_Phi = new HTuple(), hv_Length2 = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_a = new HTuple();
            HTuple hv_Rows = new HTuple(), hv_Cols = new HTuple();
            HTuple hv_j = new HTuple(), hv_R = new HTuple(), hv_C = new HTuple();
            HTuple hv_IsOverlapping = new HTuple(), hv_Dists = new HTuple();
            HTuple hv_i = new HTuple(), hv_K_V = new HTuple(), hv_K_BV = new HTuple();
            HTuple hv_R1 = new HTuple(), hv_C1 = new HTuple(), hv_Grayval = new HTuple();
            HTuple hv_Dist = new HTuple(), hv_Min = new HTuple(), hv_K_H = new HTuple();
            HTuple hv_K_BH = new HTuple(), hv_Grayval0 = new HTuple();
            HTuple hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H);
            HTuple hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V);
            HTuple hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H);
            HTuple hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V);
            HTuple hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H);
            HTuple hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V);
            HTuple hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H);
            HTuple hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V);

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_DupImage);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Contour1);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out ho_Contours1);
            HOperatorSet.GenEmptyObj(out ho_ContourV);
            HOperatorSet.GenEmptyObj(out ho_ContourH);
            HOperatorSet.GenEmptyObj(out ho_CircleV);
            HOperatorSet.GenEmptyObj(out ho_ContourH1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_CircleH);
            hv_VR = new HTuple();
            hv_VC = new HTuple();
            hv_HR = new HTuple();
            hv_HC = new HTuple();
            //参数配置*

            //像素比*
            hv_Pixel.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Pixel = hv_Parms.TupleSelect(
                    0);
            }
            //角点灰度值*
            hv_JD_Gray.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Gray = hv_Parms.TupleSelect(
                    1);
            }
            //角点距离轮廓距离*
            hv_JD_Dist.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Dist = hv_Parms.TupleSelect(
                    2);
            }
            hv_Radius_LU.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Radius_LU = hv_Parms.TupleSelect(
                    3);
            }
            //初始化*

            hv_VH_R.Dispose();
            hv_VH_R = 0;
            hv_VH_C.Dispose();
            hv_VH_C = 0;
            hv_Ra.Dispose();
            hv_Ra = 0;
            //极片竖边和小短横边交点*
            hv_VR.Dispose();
            hv_VR = 0;
            hv_VC.Dispose();
            hv_VC = 0;
            //极片横边和斜边交点*
            hv_HR.Dispose();
            hv_HR = 0;
            hv_HC.Dispose();
            hv_HC = 0;


            //V角深度和宽度*
            hv_Dist_H.Dispose();
            hv_Dist_H = 0;
            hv_Dist_W.Dispose();
            hv_Dist_W = 0;
            hv_RowBegin_H0.Dispose();
            hv_RowBegin_H0 = new HTuple(hv_RowBegin_H_COPY_INP_TMP);
            hv_ColBegin_H0.Dispose();
            hv_ColBegin_H0 = new HTuple(hv_ColBegin_H_COPY_INP_TMP);
            hv_RowEnd_H0.Dispose();
            hv_RowEnd_H0 = new HTuple(hv_RowEnd_H_COPY_INP_TMP);
            hv_ColEnd_H0.Dispose();
            hv_ColEnd_H0 = new HTuple(hv_ColEnd_H_COPY_INP_TMP);

            hv_RowBegin_V0.Dispose();
            hv_RowBegin_V0 = new HTuple(hv_RowBegin_V_COPY_INP_TMP);
            hv_ColBegin_V0.Dispose();
            hv_ColBegin_V0 = new HTuple(hv_ColBegin_V_COPY_INP_TMP);
            hv_RowEnd_V0.Dispose();
            hv_RowEnd_V0 = new HTuple(hv_RowEnd_V_COPY_INP_TMP);
            hv_ColEnd_V0.Dispose();
            hv_ColEnd_V0 = new HTuple(hv_ColEnd_V_COPY_INP_TMP);
            ho_DupImage.Dispose();
            HOperatorSet.CopyImage(ho_Image, out ho_DupImage);
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs());
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (((hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs()))).TupleAbs();
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }
            hv_Width.Dispose(); hv_Height.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);

            try
            {
                if ((int)((new HTuple((new HTuple((new HTuple((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(
                               0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(
                               new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(
                               0))))).TupleAnd(new HTuple(hv_Angle_Sub.TupleLess(0.2)))) != 0)
                {
                    //横边和竖边交点*
                    hv_Row.Dispose(); hv_Column.Dispose(); hv_IsParallel.Dispose();
                    HOperatorSet.IntersectionLl(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                        hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, hv_RowBegin_V_COPY_INP_TMP,
                        hv_ColBegin_V_COPY_INP_TMP, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP,
                        out hv_Row, out hv_Column, out hv_IsParallel);
                    //生成圆*
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius_LU / hv_Pixel);
                    HOperatorSet.DispObj(ho_Circle, hw);
                    ho_Contours.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Circle, out ho_Contours, "border");
                    ho_ImageReduced1.Dispose();
                    HOperatorSet.ReduceDomain(ho_Image, ho_Circle, out ho_ImageReduced1);
                    ho_Region.Dispose(); hv_UsedThreshold.Dispose();
                    HOperatorSet.BinaryThreshold(ho_ImageReduced1, out ho_Region, "max_separability",
                        "dark", out hv_UsedThreshold);
                    ho_RegionOpening.Dispose();
                    HOperatorSet.OpeningRectangle1(ho_Region, out ho_RegionOpening, 10, 10);
                    ho_ConnectedRegions.Dispose();
                    HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
                    hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                    HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row, out hv_Column);
                    hv_Max.Dispose();
                    HOperatorSet.TupleMax(hv_Area, out hv_Max);
                    hv_Index.Dispose();
                    HOperatorSet.TupleFindFirst(hv_Area, hv_Max, out hv_Index);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_ConnectedRegions, out ho_ObjectSelected, hv_Index + 1);
                    }
                    ho_Contour.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_ObjectSelected, out ho_Contour, "border");
                    hv_Mean.Dispose(); hv_Deviation.Dispose();
                    HOperatorSet.Intensity(ho_ObjectSelected, ho_DupImage, out hv_Mean, out hv_Deviation);
                    ho_RegionFillUp.Dispose();
                    HOperatorSet.FillUp(ho_ObjectSelected, out ho_RegionFillUp);
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_RegionFillUp, hv_Mean, "fill");
                    //外接矩形*
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1Xld(ho_Contour, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle1.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    ho_Contour1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle1, out ho_Contour1, "border");
                    //白色区域防止竖边有干扰。拟合圆不准确*
                    ho_RegionDifference.Dispose();
                    HOperatorSet.Difference(ho_Rectangle1, ho_RegionFillUp, out ho_RegionDifference
                        );
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_RegionDifference, out ExpTmpOutVar_0, 9,
                            9);
                        ho_RegionDifference.Dispose();
                        ho_RegionDifference = ExpTmpOutVar_0;
                    }
                    ho_ConnectedRegions1.Dispose();
                    HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1);
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected, 1);
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_ObjectSelected, out ExpTmpOutVar_0, 3, 3);
                        ho_ObjectSelected.Dispose();
                        ho_ObjectSelected = ExpTmpOutVar_0;
                    }
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_ObjectSelected, 255, "fill");
                    hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row11, out hv_Column11,
                        out hv_Row21, out hv_Column21);
                    ho_Rectangle2.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle2, hv_Row11, hv_Column11, hv_Row21,
                        hv_Column21);
                    ho_Contours1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle2, out ho_Contours1, "border");

                    //竖边找边*
                    hv_Row.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Row = (hv_Row21 + hv_Row2) * 0.5;
                    }
                    hv_Col.Dispose();
                    hv_Col = new HTuple(hv_Column1);
                    hv_Phi.Dispose();
                    hv_Phi = 3.14;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Row2 - hv_Row21) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 50;
                    hv_RowBegin_V_COPY_INP_TMP.Dispose(); hv_ColBegin_V_COPY_INP_TMP.Dispose(); hv_RowEnd_V_COPY_INP_TMP.Dispose(); hv_ColEnd_V_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 1, 0, out hv_RowBegin_V_COPY_INP_TMP,
                        out hv_ColBegin_V_COPY_INP_TMP, out hv_RowEnd_V_COPY_INP_TMP, out hv_ColEnd_V_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourV.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourV, hv_RowEnd_V_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_V_COPY_INP_TMP), hv_ColEnd_V_COPY_INP_TMP.TupleConcat(hv_ColBegin_V_COPY_INP_TMP));
                    }
                    //横边找边*
                    hv_Row.Dispose();
                    hv_Row = new HTuple(hv_Row1);
                    hv_Col.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Col = (hv_Column21 + hv_Column2) * 0.5;
                    }
                    hv_Phi.Dispose();
                    hv_Phi = 1.57;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Column2 - hv_Column21) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 30;
                    hv_RowBegin_H_COPY_INP_TMP.Dispose(); hv_ColBegin_H_COPY_INP_TMP.Dispose(); hv_RowEnd_H_COPY_INP_TMP.Dispose(); hv_ColEnd_H_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_H_COPY_INP_TMP,
                        out hv_ColBegin_H_COPY_INP_TMP, out hv_RowEnd_H_COPY_INP_TMP, out hv_ColEnd_H_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourH.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourH, hv_RowEnd_H_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_H_COPY_INP_TMP), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(hv_ColBegin_H_COPY_INP_TMP));
                    }

                    if ((int)((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_H_COPY_INP_TMP.Dispose();
                        hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H0);
                        hv_ColBegin_H_COPY_INP_TMP.Dispose();
                        hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H0);
                        hv_RowEnd_H_COPY_INP_TMP.Dispose();
                        hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H0);
                        hv_ColEnd_H_COPY_INP_TMP.Dispose();
                        hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H0);
                    }

                    if ((int)((new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_V_COPY_INP_TMP.Dispose();
                        hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V0);
                        hv_ColBegin_V_COPY_INP_TMP.Dispose();
                        hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V0);
                        hv_RowEnd_V_COPY_INP_TMP.Dispose();
                        hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V0);
                        hv_ColEnd_V_COPY_INP_TMP.Dispose();
                        hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V0);
                    }

                    //竖边向右平移*
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourV.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourV, hv_RowEnd_V_COPY_INP_TMP.TupleConcat(
                                hv_RowBegin_V_COPY_INP_TMP), ((hv_ColEnd_V_COPY_INP_TMP + hv_j)).TupleConcat(
                                hv_ColBegin_V_COPY_INP_TMP + hv_j));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_V_COPY_INP_TMP,
                                hv_ColBegin_V_COPY_INP_TMP + hv_j, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP + hv_j,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }

                    }

                    //挑选Rows最大值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_VR.Dispose();
                        HOperatorSet.TupleMin(hv_Rows, out hv_VR);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Rows, hv_VR, out hv_Index);
                        hv_VC.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_VC = hv_Cols.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_VR = new HTuple(hv_VR);
                            hv_VR.Dispose();
                            hv_VR = ExpTmpLocalVar_VR;
                        }
                    }
                    else
                    {
                        hv_VC.Dispose();
                        hv_VC = 0;
                        hv_VR.Dispose();
                        hv_VR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_VR, hv_VC, hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                            hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_VR.Dispose();
                        hv_VR = ExpTmpOutVar_0;
                        hv_VC.Dispose();
                        hv_VC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 0; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_V.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_V = (hv_RowEnd_V_COPY_INP_TMP - hv_RowBegin_V_COPY_INP_TMP) / ((hv_ColEnd_V_COPY_INP_TMP - hv_ColBegin_V_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BV.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BV = hv_RowEnd_V_COPY_INP_TMP - (hv_K_V * hv_ColEnd_V_COPY_INP_TMP);
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = hv_VR + hv_i;
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = (((hv_R1 - hv_K_BV) / (hv_K_V + 0.00001))).TupleCeil()
                                ;
                        }
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_VC.Dispose();
                            hv_VC = new HTuple(hv_C1);
                            hv_VR.Dispose();
                            hv_VR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleV.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleV, hv_VR, hv_VC, 0.5);
                    //斜边和长横边的交点
                    //横边向下平移*
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourH1.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourH1, ((hv_RowEnd_H_COPY_INP_TMP + hv_j)).TupleConcat(
                                hv_RowBegin_H_COPY_INP_TMP + hv_j), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(
                                hv_ColBegin_H_COPY_INP_TMP));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_H_COPY_INP_TMP + hv_j,
                                hv_ColBegin_H_COPY_INP_TMP, hv_RowEnd_H_COPY_INP_TMP + hv_j, hv_ColEnd_H_COPY_INP_TMP,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }

                    }

                    //挑选Col最小值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_HC.Dispose();
                        HOperatorSet.TupleMin(hv_Cols, out hv_HC);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Cols, hv_HC, out hv_Index);
                        hv_HR.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_HR = hv_Rows.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_HC = new HTuple(hv_HC);
                            hv_HC.Dispose();
                            hv_HC = ExpTmpLocalVar_HC;
                        }
                    }
                    else
                    {
                        hv_HC.Dispose();
                        hv_HC = 0;
                        hv_HR.Dispose();
                        hv_HR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_HR, hv_HC, hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                            hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_HR.Dispose();
                        hv_HR = ExpTmpOutVar_0;
                        hv_HC.Dispose();
                        hv_HC = ExpTmpOutVar_1;
                    }

                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 1; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_H.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_H = (hv_RowEnd_H_COPY_INP_TMP - hv_RowBegin_H_COPY_INP_TMP) / ((hv_ColEnd_H_COPY_INP_TMP - hv_ColBegin_H_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BH.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BH = hv_RowEnd_H_COPY_INP_TMP - (hv_K_H * hv_ColEnd_H_COPY_INP_TMP);
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = hv_HC + hv_i;
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = (((hv_C1 * hv_K_H) + hv_K_BH)).TupleCeil()
                                ;
                        }
                        hv_C.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C = hv_HC + hv_i;
                        }
                        hv_R.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R = (hv_C1 * hv_K_H) + hv_K_BH;
                        }
                        if ((int)(new HTuple(((hv_R - (hv_R.TupleRound()))).TupleLess(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleRound()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }
                        }
                        else
                        {

                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleFloor()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }

                        }
                        hv_Grayval0.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R, hv_C, out hv_Grayval0);
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        ho_Circle1.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle1, hv_R1, hv_C1, 0.5);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_HC.Dispose();
                            hv_HC = new HTuple(hv_C1);
                            hv_HR.Dispose();
                            hv_HR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleH.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleH, hv_HR, hv_HC, 0.5);


                }
            }
            catch (Exception)
            {

            }



            ho_DupImage.Dispose();
            ho_Circle.Dispose();
            ho_Contours.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Region.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_ObjectSelected.Dispose();
            ho_Contour.Dispose();
            ho_RegionFillUp.Dispose();
            ho_Rectangle1.Dispose();
            ho_Contour1.Dispose();
            ho_RegionDifference.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_Rectangle2.Dispose();
            ho_Contours1.Dispose();
            ho_ContourV.Dispose();
            ho_ContourH.Dispose();
            ho_CircleV.Dispose();
            ho_ContourH1.Dispose();
            ho_Circle1.Dispose();
            ho_CircleH.Dispose();

            hv_ColBegin_H_COPY_INP_TMP.Dispose();
            hv_ColBegin_V_COPY_INP_TMP.Dispose();
            hv_ColEnd_H_COPY_INP_TMP.Dispose();
            hv_ColEnd_V_COPY_INP_TMP.Dispose();
            hv_RowBegin_H_COPY_INP_TMP.Dispose();
            hv_RowBegin_V_COPY_INP_TMP.Dispose();
            hv_RowEnd_H_COPY_INP_TMP.Dispose();
            hv_RowEnd_V_COPY_INP_TMP.Dispose();
            hv_Pixel.Dispose();
            hv_JD_Gray.Dispose();
            hv_JD_Dist.Dispose();
            hv_Radius_LU.Dispose();
            hv_VH_R.Dispose();
            hv_VH_C.Dispose();
            hv_Ra.Dispose();
            hv_Dist_H.Dispose();
            hv_Dist_W.Dispose();
            hv_RowBegin_H0.Dispose();
            hv_ColBegin_H0.Dispose();
            hv_RowEnd_H0.Dispose();
            hv_ColEnd_H0.Dispose();
            hv_RowBegin_V0.Dispose();
            hv_ColBegin_V0.Dispose();
            hv_RowEnd_V0.Dispose();
            hv_ColEnd_V0.Dispose();
            hv_AngleH.Dispose();
            hv_AngleV.Dispose();
            hv_Angle.Dispose();
            hv_Angle_Sub.Dispose();
            hv_Width.Dispose();
            hv_Height.Dispose();
            hv_Row.Dispose();
            hv_Column.Dispose();
            hv_IsParallel.Dispose();
            hv_UsedThreshold.Dispose();
            hv_Area.Dispose();
            hv_Max.Dispose();
            hv_Index.Dispose();
            hv_Mean.Dispose();
            hv_Deviation.Dispose();
            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Row11.Dispose();
            hv_Column11.Dispose();
            hv_Row21.Dispose();
            hv_Column21.Dispose();
            hv_Col.Dispose();
            hv_Phi.Dispose();
            hv_Length2.Dispose();
            hv_Length1.Dispose();
            hv_a.Dispose();
            hv_Rows.Dispose();
            hv_Cols.Dispose();
            hv_j.Dispose();
            hv_R.Dispose();
            hv_C.Dispose();
            hv_IsOverlapping.Dispose();
            hv_Dists.Dispose();
            hv_i.Dispose();
            hv_K_V.Dispose();
            hv_K_BV.Dispose();
            hv_R1.Dispose();
            hv_C1.Dispose();
            hv_Grayval.Dispose();
            hv_Dist.Dispose();
            hv_Min.Dispose();
            hv_K_H.Dispose();
            hv_K_BH.Dispose();
            hv_Grayval0.Dispose();

            return;
        }

        public static void Detect_RD_V(HObject ho_Image, HWindow hw, HTuple hv_Parms, HTuple hv_RowBegin_H,
            HTuple hv_ColBegin_H, HTuple hv_RowEnd_H, HTuple hv_ColEnd_H, HTuple hv_RowBegin_V,
            HTuple hv_ColBegin_V, HTuple hv_RowEnd_V, HTuple hv_ColEnd_V, out HTuple hv_VR,
            out HTuple hv_VC, out HTuple hv_HR, out HTuple hv_HC)
        {

            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_DupImage, ho_Circle = null, ho_Contours = null;
            HObject ho_ImageReduced1 = null, ho_Region = null, ho_RegionOpening = null;
            HObject ho_ConnectedRegions = null, ho_ObjectSelected = null;
            HObject ho_Contour = null, ho_RegionFillUp = null, ho_Rectangle1 = null;
            HObject ho_Contour1 = null, ho_RegionDifference = null, ho_ConnectedRegions1 = null;
            HObject ho_Rectangle2 = null, ho_Contours1 = null, ho_ContourV = null;
            HObject ho_ContourH = null, ho_ContourV1 = null, ho_CircleV = null;
            HObject ho_ContourH1 = null, ho_Circle1 = null, ho_CircleH = null;

            // Local control variables 

            HTuple hv_Pixel = new HTuple(), hv_JD_Gray = new HTuple();
            HTuple hv_JD_Dist = new HTuple(), hv_Radius_RD = new HTuple();
            HTuple hv_VH_R = new HTuple(), hv_VH_C = new HTuple();
            HTuple hv_Ra = new HTuple(), hv_Dist_W = new HTuple();
            HTuple hv_Dist_H = new HTuple(), hv_RowBegin_H0 = new HTuple();
            HTuple hv_ColBegin_H0 = new HTuple(), hv_RowEnd_H0 = new HTuple();
            HTuple hv_ColEnd_H0 = new HTuple(), hv_RowBegin_V0 = new HTuple();
            HTuple hv_ColBegin_V0 = new HTuple(), hv_RowEnd_V0 = new HTuple();
            HTuple hv_ColEnd_V0 = new HTuple(), hv_AngleH = new HTuple();
            HTuple hv_AngleV = new HTuple(), hv_Angle = new HTuple();
            HTuple hv_Angle_Sub = new HTuple(), hv_Row = new HTuple();
            HTuple hv_Column = new HTuple(), hv_IsParallel = new HTuple();
            HTuple hv_UsedThreshold = new HTuple(), hv_Area = new HTuple();
            HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Mean = new HTuple(), hv_Deviation = new HTuple();
            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
            HTuple hv_Row21 = new HTuple(), hv_Column21 = new HTuple();
            HTuple hv_Col = new HTuple(), hv_Phi = new HTuple(), hv_Length2 = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_a = new HTuple();
            HTuple hv_Rows = new HTuple(), hv_Cols = new HTuple();
            HTuple hv_j = new HTuple(), hv_R = new HTuple(), hv_C = new HTuple();
            HTuple hv_IsOverlapping = new HTuple(), hv_Dists = new HTuple();
            HTuple hv_i = new HTuple(), hv_K_V = new HTuple(), hv_K_BV = new HTuple();
            HTuple hv_R1 = new HTuple(), hv_C1 = new HTuple(), hv_Grayval = new HTuple();
            HTuple hv_Dist = new HTuple(), hv_Min = new HTuple(), hv_K_H = new HTuple();
            HTuple hv_K_BH = new HTuple(), hv_Grayval0 = new HTuple();
            HTuple hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H);
            HTuple hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V);
            HTuple hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H);
            HTuple hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V);
            HTuple hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H);
            HTuple hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V);
            HTuple hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H);
            HTuple hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V);

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_DupImage);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Contour1);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out ho_Contours1);
            HOperatorSet.GenEmptyObj(out ho_ContourV);
            HOperatorSet.GenEmptyObj(out ho_ContourH);
            HOperatorSet.GenEmptyObj(out ho_ContourV1);
            HOperatorSet.GenEmptyObj(out ho_CircleV);
            HOperatorSet.GenEmptyObj(out ho_ContourH1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_CircleH);
            hv_VR = new HTuple();
            hv_VC = new HTuple();
            hv_HR = new HTuple();
            hv_HC = new HTuple();

            //参数配置*
            hv_Pixel.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Pixel = hv_Parms.TupleSelect(
                    0);
            }
            //角点灰度值*
            hv_JD_Gray.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Gray = hv_Parms.TupleSelect(
                    1);
            }
            //角点距离轮廓距离*
            hv_JD_Dist.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Dist = hv_Parms.TupleSelect(
                    2);
            }
            //右角圆半径*
            hv_Radius_RD.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Radius_RD = hv_Parms.TupleSelect(
                    3);
            }

            //初始化*
            hv_VH_R.Dispose();
            hv_VH_R = 0;
            hv_VH_C.Dispose();
            hv_VH_C = 0;
            hv_Ra.Dispose();
            hv_Ra = 0;

            hv_VR.Dispose();
            hv_VR = 0;
            hv_VC.Dispose();
            hv_VC = 0;
            hv_HR.Dispose();
            hv_HR = 0;
            hv_HC.Dispose();
            hv_HC = 0;
            hv_Dist_W.Dispose();
            hv_Dist_W = 0;
            hv_Dist_H.Dispose();
            hv_Dist_H = 0;
            hv_RowBegin_H0.Dispose();
            hv_RowBegin_H0 = new HTuple(hv_RowBegin_H_COPY_INP_TMP);
            hv_ColBegin_H0.Dispose();
            hv_ColBegin_H0 = new HTuple(hv_ColBegin_H_COPY_INP_TMP);
            hv_RowEnd_H0.Dispose();
            hv_RowEnd_H0 = new HTuple(hv_RowEnd_H_COPY_INP_TMP);
            hv_ColEnd_H0.Dispose();
            hv_ColEnd_H0 = new HTuple(hv_ColEnd_H_COPY_INP_TMP);

            hv_RowBegin_V0.Dispose();
            hv_RowBegin_V0 = new HTuple(hv_RowBegin_V_COPY_INP_TMP);
            hv_ColBegin_V0.Dispose();
            hv_ColBegin_V0 = new HTuple(hv_ColBegin_V_COPY_INP_TMP);
            hv_RowEnd_V0.Dispose();
            hv_RowEnd_V0 = new HTuple(hv_RowEnd_V_COPY_INP_TMP);
            hv_ColEnd_V0.Dispose();
            hv_ColEnd_V0 = new HTuple(hv_ColEnd_V_COPY_INP_TMP);
            ho_DupImage.Dispose();
            HOperatorSet.CopyImage(ho_Image, out ho_DupImage);
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (((hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs()))).TupleAbs();
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }

            try
            {
                if ((int)((new HTuple((new HTuple((new HTuple((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(
                    0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(
                    new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(
                    0))))).TupleAnd(new HTuple(hv_Angle_Sub.TupleLess(0.2)))) != 0)
                {

                    //横边和竖边交点*
                    hv_Row.Dispose(); hv_Column.Dispose(); hv_IsParallel.Dispose();
                    HOperatorSet.IntersectionLl(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                        hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, hv_RowBegin_V_COPY_INP_TMP,
                        hv_ColBegin_V_COPY_INP_TMP, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP,
                        out hv_Row, out hv_Column, out hv_IsParallel);
                    //生成圆*
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius_RD / hv_Pixel);
                    HOperatorSet.DispObj(ho_Circle, hw);
                    ho_Contours.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Circle, out ho_Contours, "border");
                    ho_ImageReduced1.Dispose();
                    HOperatorSet.ReduceDomain(ho_Image, ho_Circle, out ho_ImageReduced1);
                    ho_Region.Dispose(); hv_UsedThreshold.Dispose();
                    HOperatorSet.BinaryThreshold(ho_ImageReduced1, out ho_Region, "max_separability",
                        "dark", out hv_UsedThreshold);
                    ho_RegionOpening.Dispose();
                    HOperatorSet.OpeningRectangle1(ho_Region, out ho_RegionOpening, 10, 10);
                    ho_ConnectedRegions.Dispose();
                    HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
                    hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                    HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row, out hv_Column);
                    hv_Max.Dispose();
                    HOperatorSet.TupleMax(hv_Area, out hv_Max);
                    hv_Index.Dispose();
                    HOperatorSet.TupleFindFirst(hv_Area, hv_Max, out hv_Index);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_ConnectedRegions, out ho_ObjectSelected, hv_Index + 1);
                    }
                    ho_Contour.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_ObjectSelected, out ho_Contour, "border");
                    hv_Mean.Dispose(); hv_Deviation.Dispose();
                    HOperatorSet.Intensity(ho_ObjectSelected, ho_DupImage, out hv_Mean, out hv_Deviation);
                    ho_RegionFillUp.Dispose();
                    HOperatorSet.FillUp(ho_ObjectSelected, out ho_RegionFillUp);
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_RegionFillUp, hv_Mean, "fill");
                    //外接矩形*
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1Xld(ho_Contour, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle1.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    ho_Contour1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle1, out ho_Contour1, "border");
                    //白色区域防止竖边有干扰。拟合圆不准确*
                    ho_RegionDifference.Dispose();
                    HOperatorSet.Difference(ho_Rectangle1, ho_RegionFillUp, out ho_RegionDifference
                        );
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_RegionDifference, out ExpTmpOutVar_0, 9,
                            9);
                        ho_RegionDifference.Dispose();
                        ho_RegionDifference = ExpTmpOutVar_0;
                    }
                    ho_ConnectedRegions1.Dispose();
                    HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1);
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected, 2);
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_ObjectSelected, out ExpTmpOutVar_0, 3, 3);
                        ho_ObjectSelected.Dispose();
                        ho_ObjectSelected = ExpTmpOutVar_0;
                    }
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_ObjectSelected, 255, "fill");
                    hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row11, out hv_Column11,
                        out hv_Row21, out hv_Column21);
                    ho_Rectangle2.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle2, hv_Row11, hv_Column11, hv_Row21,
                        hv_Column21);
                    ho_Contours1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle2, out ho_Contours1, "border");

                    //竖边找边*
                    hv_Row.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Row = (hv_Row1 + hv_Row11) * 0.5;
                    }
                    hv_Col.Dispose();
                    hv_Col = new HTuple(hv_Column2);
                    hv_Phi.Dispose();
                    hv_Phi = 0;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Row11 - hv_Row1) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 50;
                    hv_RowBegin_V_COPY_INP_TMP.Dispose(); hv_ColBegin_V_COPY_INP_TMP.Dispose(); hv_RowEnd_V_COPY_INP_TMP.Dispose(); hv_ColEnd_V_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_V_COPY_INP_TMP,
                        out hv_ColBegin_V_COPY_INP_TMP, out hv_RowEnd_V_COPY_INP_TMP, out hv_ColEnd_V_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourV.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourV, hv_RowEnd_V_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_V_COPY_INP_TMP), hv_ColEnd_V_COPY_INP_TMP.TupleConcat(hv_ColBegin_V_COPY_INP_TMP));
                    }
                    //横边找边*
                    hv_Row.Dispose();
                    hv_Row = new HTuple(hv_Row2);
                    hv_Col.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Col = (hv_Column1 + hv_Column11) * 0.5;
                    }
                    hv_Phi.Dispose();
                    hv_Phi = -1.57;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Column11 - hv_Column1) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 50;
                    hv_RowBegin_H_COPY_INP_TMP.Dispose(); hv_ColBegin_H_COPY_INP_TMP.Dispose(); hv_RowEnd_H_COPY_INP_TMP.Dispose(); hv_ColEnd_H_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_H_COPY_INP_TMP,
                        out hv_ColBegin_H_COPY_INP_TMP, out hv_RowEnd_H_COPY_INP_TMP, out hv_ColEnd_H_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourH.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourH, hv_RowEnd_H_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_H_COPY_INP_TMP), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(hv_ColBegin_H_COPY_INP_TMP));
                    }

                    if ((int)((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_H_COPY_INP_TMP.Dispose();
                        hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H0);
                        hv_ColBegin_H_COPY_INP_TMP.Dispose();
                        hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H0);
                        hv_RowEnd_H_COPY_INP_TMP.Dispose();
                        hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H0);
                        hv_ColEnd_H_COPY_INP_TMP.Dispose();
                        hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H0);
                    }

                    if ((int)((new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_V_COPY_INP_TMP.Dispose();
                        hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V0);
                        hv_ColBegin_V_COPY_INP_TMP.Dispose();
                        hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V0);
                        hv_RowEnd_V_COPY_INP_TMP.Dispose();
                        hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V0);
                        hv_ColEnd_V_COPY_INP_TMP.Dispose();
                        hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V0);
                    }

                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    //竖边向左平移*
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourV1.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourV1, hv_RowEnd_V_COPY_INP_TMP.TupleConcat(
                                hv_RowBegin_V_COPY_INP_TMP), ((hv_ColEnd_V_COPY_INP_TMP - hv_j)).TupleConcat(
                                hv_ColBegin_V_COPY_INP_TMP - hv_j));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_V_COPY_INP_TMP,
                                hv_ColBegin_V_COPY_INP_TMP - hv_j, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP - hv_j,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }

                    }

                    //挑选Rows最大值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_VR.Dispose();
                        HOperatorSet.TupleMax(hv_Rows, out hv_VR);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Rows, hv_VR, out hv_Index);
                        hv_VC.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_VC = hv_Cols.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_VR = new HTuple(hv_VR);
                            hv_VR.Dispose();
                            hv_VR = ExpTmpLocalVar_VR;
                        }
                    }
                    else
                    {
                        hv_VC.Dispose();
                        hv_VC = 0;
                        hv_VR.Dispose();
                        hv_VR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_VR, hv_VC, hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                            hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_VR.Dispose();
                        hv_VR = ExpTmpOutVar_0;
                        hv_VC.Dispose();
                        hv_VC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 0; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_V.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_V = (hv_RowEnd_V_COPY_INP_TMP - hv_RowBegin_V_COPY_INP_TMP) / ((hv_ColEnd_V_COPY_INP_TMP - hv_ColBegin_V_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BV.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BV = hv_RowEnd_V_COPY_INP_TMP - (hv_K_V * hv_ColEnd_V_COPY_INP_TMP);
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = hv_VR - hv_i;
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = (((hv_R1 - hv_K_BV) / (hv_K_V + 0.00001))).TupleFloor()
                                ;
                        }
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_VC.Dispose();
                            hv_VC = new HTuple(hv_C1);
                            hv_VR.Dispose();
                            hv_VR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleV.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleV, hv_VR, hv_VC, 0.5);

                    //轮廓和长横边的交点*
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourH1.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourH1, ((hv_RowEnd_H_COPY_INP_TMP - hv_j)).TupleConcat(
                                hv_RowBegin_H_COPY_INP_TMP - hv_j), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(
                                hv_ColBegin_H_COPY_INP_TMP));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_H_COPY_INP_TMP - hv_j,
                                hv_ColBegin_H_COPY_INP_TMP, hv_RowEnd_H_COPY_INP_TMP - hv_j, hv_ColEnd_H_COPY_INP_TMP,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }
                    }

                    //挑选Col最大值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_HC.Dispose();
                        HOperatorSet.TupleMax(hv_Cols, out hv_HC);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Cols, hv_HC, out hv_Index);
                        hv_HR.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_HR = hv_Rows.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_HC = new HTuple(hv_HC);
                            hv_HC.Dispose();
                            hv_HC = ExpTmpLocalVar_HC;
                        }
                    }
                    else
                    {
                        hv_HC.Dispose();
                        hv_HC = 0;
                        hv_HR.Dispose();
                        hv_HR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_HR, hv_HC, hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                            hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_HR.Dispose();
                        hv_HR = ExpTmpOutVar_0;
                        hv_HC.Dispose();
                        hv_HC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 1; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_H.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_H = (hv_RowEnd_H_COPY_INP_TMP - hv_RowBegin_H_COPY_INP_TMP) / ((hv_ColEnd_H_COPY_INP_TMP - hv_ColBegin_H_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BH.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BH = hv_RowEnd_H_COPY_INP_TMP - (hv_K_H * hv_ColEnd_H_COPY_INP_TMP);
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = hv_HC - hv_i;
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = (((hv_C1 * hv_K_H) + hv_K_BH)).TupleFloor()
                                ;
                        }
                        hv_C.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C = hv_HC - hv_i;
                        }
                        hv_R.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R = (hv_C1 * hv_K_H) + hv_K_BH;
                        }
                        if ((int)(new HTuple(((hv_R - (hv_R.TupleRound()))).TupleLess(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleRound()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }
                        }
                        else
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleFloor()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }

                        }
                        hv_Grayval0.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R, hv_C, out hv_Grayval0);
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        ho_Circle1.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle1, hv_R1, hv_C1, 0.5);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_HC.Dispose();
                            hv_HC = new HTuple(hv_C1);
                            hv_HR.Dispose();
                            hv_HR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleH.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleH, hv_HR, hv_HC, 0.5);


                }
            }
            catch (Exception)
            {

            }
            ho_DupImage.Dispose();
            ho_Circle.Dispose();
            ho_Contours.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Region.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_ObjectSelected.Dispose();
            ho_Contour.Dispose();
            ho_RegionFillUp.Dispose();
            ho_Rectangle1.Dispose();
            ho_Contour1.Dispose();
            ho_RegionDifference.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_Rectangle2.Dispose();
            ho_Contours1.Dispose();
            ho_ContourV.Dispose();
            ho_ContourH.Dispose();
            ho_ContourV1.Dispose();
            ho_CircleV.Dispose();
            ho_ContourH1.Dispose();
            ho_Circle1.Dispose();
            ho_CircleH.Dispose();

            hv_ColBegin_H_COPY_INP_TMP.Dispose();
            hv_ColBegin_V_COPY_INP_TMP.Dispose();
            hv_ColEnd_H_COPY_INP_TMP.Dispose();
            hv_ColEnd_V_COPY_INP_TMP.Dispose();
            hv_RowBegin_H_COPY_INP_TMP.Dispose();
            hv_RowBegin_V_COPY_INP_TMP.Dispose();
            hv_RowEnd_H_COPY_INP_TMP.Dispose();
            hv_RowEnd_V_COPY_INP_TMP.Dispose();
            hv_Pixel.Dispose();
            hv_JD_Gray.Dispose();
            hv_JD_Dist.Dispose();
            hv_Radius_RD.Dispose();
            hv_VH_R.Dispose();
            hv_VH_C.Dispose();
            hv_Ra.Dispose();
            hv_Dist_W.Dispose();
            hv_Dist_H.Dispose();
            hv_RowBegin_H0.Dispose();
            hv_ColBegin_H0.Dispose();
            hv_RowEnd_H0.Dispose();
            hv_ColEnd_H0.Dispose();
            hv_RowBegin_V0.Dispose();
            hv_ColBegin_V0.Dispose();
            hv_RowEnd_V0.Dispose();
            hv_ColEnd_V0.Dispose();
            hv_AngleH.Dispose();
            hv_AngleV.Dispose();
            hv_Angle.Dispose();
            hv_Angle_Sub.Dispose();
            hv_Row.Dispose();
            hv_Column.Dispose();
            hv_IsParallel.Dispose();
            hv_UsedThreshold.Dispose();
            hv_Area.Dispose();
            hv_Max.Dispose();
            hv_Index.Dispose();
            hv_Mean.Dispose();
            hv_Deviation.Dispose();
            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Row11.Dispose();
            hv_Column11.Dispose();
            hv_Row21.Dispose();
            hv_Column21.Dispose();
            hv_Col.Dispose();
            hv_Phi.Dispose();
            hv_Length2.Dispose();
            hv_Length1.Dispose();
            hv_a.Dispose();
            hv_Rows.Dispose();
            hv_Cols.Dispose();
            hv_j.Dispose();
            hv_R.Dispose();
            hv_C.Dispose();
            hv_IsOverlapping.Dispose();
            hv_Dists.Dispose();
            hv_i.Dispose();
            hv_K_V.Dispose();
            hv_K_BV.Dispose();
            hv_R1.Dispose();
            hv_C1.Dispose();
            hv_Grayval.Dispose();
            hv_Dist.Dispose();
            hv_Min.Dispose();
            hv_K_H.Dispose();
            hv_K_BH.Dispose();
            hv_Grayval0.Dispose();

            return;
        }

        public static void Detect_RU_V(HObject ho_Image, HWindow hw, HTuple hv_Parms, HTuple hv_RowBegin_H,
            HTuple hv_ColBegin_H, HTuple hv_RowEnd_H, HTuple hv_ColEnd_H, HTuple hv_RowBegin_V,
            HTuple hv_ColBegin_V, HTuple hv_RowEnd_V, HTuple hv_ColEnd_V, out HTuple hv_VR,
            out HTuple hv_VC, out HTuple hv_HR, out HTuple hv_HC)
        {




            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_DupImage, ho_Circle = null, ho_Contours = null;
            HObject ho_ImageReduced1 = null, ho_Region = null, ho_RegionOpening = null;
            HObject ho_ConnectedRegions = null, ho_ObjectSelected = null;
            HObject ho_Contour = null, ho_RegionFillUp = null, ho_Rectangle1 = null;
            HObject ho_Contour1 = null, ho_RegionDifference = null, ho_ConnectedRegions1 = null;
            HObject ho_Rectangle2 = null, ho_Contours1 = null, ho_ContourV = null;
            HObject ho_ContourH = null, ho_CircleV = null, ho_ContourH1 = null;
            HObject ho_Circle1 = null, ho_CircleH = null;

            // Local control variables 

            HTuple hv_Pixel = new HTuple(), hv_JD_Gray = new HTuple();
            HTuple hv_JD_Dist = new HTuple(), hv_Radius_RU = new HTuple();
            HTuple hv_VH_R = new HTuple(), hv_VH_C = new HTuple();
            HTuple hv_Ra = new HTuple(), hv_Dist_H = new HTuple();
            HTuple hv_Dist_W = new HTuple(), hv_RowBegin_H0 = new HTuple();
            HTuple hv_ColBegin_H0 = new HTuple(), hv_RowEnd_H0 = new HTuple();
            HTuple hv_ColEnd_H0 = new HTuple(), hv_RowBegin_V0 = new HTuple();
            HTuple hv_ColBegin_V0 = new HTuple(), hv_RowEnd_V0 = new HTuple();
            HTuple hv_ColEnd_V0 = new HTuple(), hv_AngleH = new HTuple();
            HTuple hv_AngleV = new HTuple(), hv_Angle = new HTuple();
            HTuple hv_Angle_Sub = new HTuple(), hv_Width = new HTuple();
            HTuple hv_Height = new HTuple(), hv_Row = new HTuple();
            HTuple hv_Column = new HTuple(), hv_IsParallel = new HTuple();
            HTuple hv_UsedThreshold = new HTuple(), hv_Area = new HTuple();
            HTuple hv_Max = new HTuple(), hv_Index = new HTuple();
            HTuple hv_Mean = new HTuple(), hv_Deviation = new HTuple();
            HTuple hv_Row1 = new HTuple(), hv_Column1 = new HTuple();
            HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
            HTuple hv_Row11 = new HTuple(), hv_Column11 = new HTuple();
            HTuple hv_Row21 = new HTuple(), hv_Column21 = new HTuple();
            HTuple hv_Col = new HTuple(), hv_Phi = new HTuple(), hv_Length2 = new HTuple();
            HTuple hv_Length1 = new HTuple(), hv_a = new HTuple();
            HTuple hv_Rows = new HTuple(), hv_Cols = new HTuple();
            HTuple hv_j = new HTuple(), hv_R = new HTuple(), hv_C = new HTuple();
            HTuple hv_IsOverlapping = new HTuple(), hv_Dists = new HTuple();
            HTuple hv_i = new HTuple(), hv_K_V = new HTuple(), hv_K_BV = new HTuple();
            HTuple hv_R1 = new HTuple(), hv_C1 = new HTuple(), hv_Grayval = new HTuple();
            HTuple hv_Dist = new HTuple(), hv_Min = new HTuple(), hv_K_H = new HTuple();
            HTuple hv_K_BH = new HTuple(), hv_Grayval0 = new HTuple();
            HTuple hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H);
            HTuple hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V);
            HTuple hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H);
            HTuple hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V);
            HTuple hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H);
            HTuple hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V);
            HTuple hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H);
            HTuple hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V);

            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_DupImage);
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Contour1);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_Rectangle2);
            HOperatorSet.GenEmptyObj(out ho_Contours1);
            HOperatorSet.GenEmptyObj(out ho_ContourV);
            HOperatorSet.GenEmptyObj(out ho_ContourH);
            HOperatorSet.GenEmptyObj(out ho_CircleV);
            HOperatorSet.GenEmptyObj(out ho_ContourH1);
            HOperatorSet.GenEmptyObj(out ho_Circle1);
            HOperatorSet.GenEmptyObj(out ho_CircleH);
            hv_VR = new HTuple();
            hv_VC = new HTuple();
            hv_HR = new HTuple();
            hv_HC = new HTuple();
            //参数配置*

            //像素比例*
            hv_Pixel.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Pixel = hv_Parms.TupleSelect(
                    0);
            }
            //角点灰度值*
            hv_JD_Gray.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Gray = hv_Parms.TupleSelect(
                    1);
            }
            //角点距离轮廓距离*
            hv_JD_Dist.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_JD_Dist = hv_Parms.TupleSelect(
                    2);
            }
            hv_Radius_RU.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Radius_RU = hv_Parms.TupleSelect(
                    3);
            }
            //初始化*
            //极片竖边和小短横边交点*
            hv_VH_R.Dispose();
            hv_VH_R = 0;
            hv_VH_C.Dispose();
            hv_VH_C = 0;
            hv_Ra.Dispose();
            hv_Ra = 0;

            hv_VR.Dispose();
            hv_VR = 0;
            hv_VC.Dispose();
            hv_VC = 0;
            //极片横边和斜边交点*
            hv_HR.Dispose();
            hv_HR = 0;
            hv_HC.Dispose();
            hv_HC = 0;
            hv_Dist_H.Dispose();
            hv_Dist_H = 0;
            hv_Dist_W.Dispose();
            hv_Dist_W = 0;
            hv_RowBegin_H0.Dispose();
            hv_RowBegin_H0 = new HTuple(hv_RowBegin_H_COPY_INP_TMP);
            hv_ColBegin_H0.Dispose();
            hv_ColBegin_H0 = new HTuple(hv_ColBegin_H_COPY_INP_TMP);
            hv_RowEnd_H0.Dispose();
            hv_RowEnd_H0 = new HTuple(hv_RowEnd_H_COPY_INP_TMP);
            hv_ColEnd_H0.Dispose();
            hv_ColEnd_H0 = new HTuple(hv_ColEnd_H_COPY_INP_TMP);

            hv_RowBegin_V0.Dispose();
            hv_RowBegin_V0 = new HTuple(hv_RowBegin_V_COPY_INP_TMP);
            hv_ColBegin_V0.Dispose();
            hv_ColBegin_V0 = new HTuple(hv_ColBegin_V_COPY_INP_TMP);
            hv_RowEnd_V0.Dispose();
            hv_RowEnd_V0 = new HTuple(hv_RowEnd_V_COPY_INP_TMP);
            hv_ColEnd_V0.Dispose();
            hv_ColEnd_V0 = new HTuple(hv_ColEnd_V_COPY_INP_TMP);
            ho_DupImage.Dispose();
            HOperatorSet.CopyImage(ho_Image, out ho_DupImage);
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs());
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }
            hv_AngleH.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out hv_AngleH);
            hv_AngleV.Dispose();
            HOperatorSet.AngleLx(hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out hv_AngleV);
            hv_Angle.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle = (((hv_AngleH.TupleAbs()
                    ) - (hv_AngleV.TupleAbs()))).TupleAbs();
            }
            hv_Angle_Sub.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_Angle_Sub = ((hv_Angle - 1.57)).TupleAbs()
                    ;
            }
            hv_Width.Dispose(); hv_Height.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);

            try
            {


                if ((int)((new HTuple((new HTuple((new HTuple((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(
                    0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(
                    new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(0))))).TupleAnd(new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(
                    0))))).TupleAnd(new HTuple(hv_Angle_Sub.TupleLess(0.2)))) != 0)
                {

                    //横边和竖边交点*
                    hv_Row.Dispose(); hv_Column.Dispose(); hv_IsParallel.Dispose();
                    HOperatorSet.IntersectionLl(hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                        hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, hv_RowBegin_V_COPY_INP_TMP,
                        hv_ColBegin_V_COPY_INP_TMP, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP,
                        out hv_Row, out hv_Column, out hv_IsParallel);
                    //生成圆*
                    ho_Circle.Dispose();
                    HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius_RU / hv_Pixel);
                    HOperatorSet.DispObj(ho_Circle, hw);
                    ho_Contours.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Circle, out ho_Contours, "border");
                    ho_ImageReduced1.Dispose();
                    HOperatorSet.ReduceDomain(ho_Image, ho_Circle, out ho_ImageReduced1);
                    ho_Region.Dispose(); hv_UsedThreshold.Dispose();
                    HOperatorSet.BinaryThreshold(ho_ImageReduced1, out ho_Region, "max_separability",
                        "dark", out hv_UsedThreshold);
                    ho_RegionOpening.Dispose();
                    HOperatorSet.OpeningRectangle1(ho_Region, out ho_RegionOpening, 10, 10);
                    ho_ConnectedRegions.Dispose();
                    HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
                    hv_Area.Dispose(); hv_Row.Dispose(); hv_Column.Dispose();
                    HOperatorSet.AreaCenter(ho_ConnectedRegions, out hv_Area, out hv_Row, out hv_Column);
                    hv_Max.Dispose();
                    HOperatorSet.TupleMax(hv_Area, out hv_Max);
                    hv_Index.Dispose();
                    HOperatorSet.TupleFindFirst(hv_Area, hv_Max, out hv_Index);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ObjectSelected.Dispose();
                        HOperatorSet.SelectObj(ho_ConnectedRegions, out ho_ObjectSelected, hv_Index + 1);
                    }
                    ho_Contour.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_ObjectSelected, out ho_Contour, "border");
                    hv_Mean.Dispose(); hv_Deviation.Dispose();
                    HOperatorSet.Intensity(ho_ObjectSelected, ho_DupImage, out hv_Mean, out hv_Deviation);
                    ho_RegionFillUp.Dispose();
                    HOperatorSet.FillUp(ho_ObjectSelected, out ho_RegionFillUp);
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_RegionFillUp, hv_Mean, "fill");
                    //外接矩形*
                    hv_Row1.Dispose(); hv_Column1.Dispose(); hv_Row2.Dispose(); hv_Column2.Dispose();
                    HOperatorSet.SmallestRectangle1Xld(ho_Contour, out hv_Row1, out hv_Column1,
                        out hv_Row2, out hv_Column2);
                    ho_Rectangle1.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Row2,
                        hv_Column2);
                    ho_Contour1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle1, out ho_Contour1, "border");
                    //白色区域防止竖边有干扰。拟合圆不准确*
                    ho_RegionDifference.Dispose();
                    HOperatorSet.Difference(ho_Rectangle1, ho_RegionFillUp, out ho_RegionDifference
                        );
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_RegionDifference, out ExpTmpOutVar_0, 9,
                            9);
                        ho_RegionDifference.Dispose();
                        ho_RegionDifference = ExpTmpOutVar_0;
                    }
                    ho_ConnectedRegions1.Dispose();
                    HOperatorSet.Connection(ho_RegionDifference, out ho_ConnectedRegions1);
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_ConnectedRegions1, out ho_ObjectSelected, 1);
                    {
                        HObject ExpTmpOutVar_0;
                        HOperatorSet.OpeningRectangle1(ho_ObjectSelected, out ExpTmpOutVar_0, 3, 3);
                        ho_ObjectSelected.Dispose();
                        ho_ObjectSelected = ExpTmpOutVar_0;
                    }
                    HOperatorSet.OverpaintRegion(ho_DupImage, ho_ObjectSelected, 255, "fill");
                    hv_Row11.Dispose(); hv_Column11.Dispose(); hv_Row21.Dispose(); hv_Column21.Dispose();
                    HOperatorSet.SmallestRectangle1(ho_ObjectSelected, out hv_Row11, out hv_Column11,
                        out hv_Row21, out hv_Column21);
                    ho_Rectangle2.Dispose();
                    HOperatorSet.GenRectangle1(out ho_Rectangle2, hv_Row11, hv_Column11, hv_Row21,
                        hv_Column21);
                    ho_Contours1.Dispose();
                    HOperatorSet.GenContourRegionXld(ho_Rectangle2, out ho_Contours1, "border");

                    //竖边找边*
                    hv_Row.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Row = (hv_Row21 + hv_Row2) * 0.5;
                    }
                    hv_Col.Dispose();
                    hv_Col = new HTuple(hv_Column2);
                    hv_Phi.Dispose();
                    hv_Phi = 0;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Row2 - hv_Row21) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 50;
                    hv_RowBegin_V_COPY_INP_TMP.Dispose(); hv_ColBegin_V_COPY_INP_TMP.Dispose(); hv_RowEnd_V_COPY_INP_TMP.Dispose(); hv_ColEnd_V_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_V_COPY_INP_TMP,
                        out hv_ColBegin_V_COPY_INP_TMP, out hv_RowEnd_V_COPY_INP_TMP, out hv_ColEnd_V_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourV.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourV, hv_RowEnd_V_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_V_COPY_INP_TMP), hv_ColEnd_V_COPY_INP_TMP.TupleConcat(hv_ColBegin_V_COPY_INP_TMP));
                    }
                    //横边找边*
                    hv_Row.Dispose();
                    hv_Row = new HTuple(hv_Row1);
                    hv_Col.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Col = (hv_Column1 + hv_Column11) * 0.5;
                    }
                    hv_Phi.Dispose();
                    hv_Phi = 1.57;
                    hv_Length2.Dispose();
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        hv_Length2 = (hv_Column11 - hv_Column1) * 0.4;
                    }
                    hv_Length1.Dispose();
                    hv_Length1 = 30;
                    hv_RowBegin_H_COPY_INP_TMP.Dispose(); hv_ColBegin_H_COPY_INP_TMP.Dispose(); hv_RowEnd_H_COPY_INP_TMP.Dispose(); hv_ColEnd_H_COPY_INP_TMP.Dispose();
                    rake_edge(ho_DupImage, hv_Row, hv_Col, hv_Phi, hv_Length1, hv_Length2, 3, 1,
                        40, "positive", "first", "TRUE", "FALSE", "TRUE", 0, 1, out hv_RowBegin_H_COPY_INP_TMP,
                        out hv_ColBegin_H_COPY_INP_TMP, out hv_RowEnd_H_COPY_INP_TMP, out hv_ColEnd_H_COPY_INP_TMP);
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_ContourH.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_ContourH, hv_RowEnd_H_COPY_INP_TMP.TupleConcat(
                            hv_RowBegin_H_COPY_INP_TMP), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(hv_ColBegin_H_COPY_INP_TMP));
                    }

                    if ((int)((new HTuple(hv_RowEnd_H_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_H_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_H_COPY_INP_TMP.Dispose();
                        hv_RowBegin_H_COPY_INP_TMP = new HTuple(hv_RowBegin_H0);
                        hv_ColBegin_H_COPY_INP_TMP.Dispose();
                        hv_ColBegin_H_COPY_INP_TMP = new HTuple(hv_ColBegin_H0);
                        hv_RowEnd_H_COPY_INP_TMP.Dispose();
                        hv_RowEnd_H_COPY_INP_TMP = new HTuple(hv_RowEnd_H0);
                        hv_ColEnd_H_COPY_INP_TMP.Dispose();
                        hv_ColEnd_H_COPY_INP_TMP = new HTuple(hv_ColEnd_H0);
                    }

                    if ((int)((new HTuple(hv_RowEnd_V_COPY_INP_TMP.TupleGreater(0))).TupleAnd(new HTuple(hv_RowBegin_V_COPY_INP_TMP.TupleGreater(
                        0)))) != 0)
                    {
                        hv_a.Dispose();
                        hv_a = 1;
                    }
                    else
                    {
                        hv_RowBegin_V_COPY_INP_TMP.Dispose();
                        hv_RowBegin_V_COPY_INP_TMP = new HTuple(hv_RowBegin_V0);
                        hv_ColBegin_V_COPY_INP_TMP.Dispose();
                        hv_ColBegin_V_COPY_INP_TMP = new HTuple(hv_ColBegin_V0);
                        hv_RowEnd_V_COPY_INP_TMP.Dispose();
                        hv_RowEnd_V_COPY_INP_TMP = new HTuple(hv_RowEnd_V0);
                        hv_ColEnd_V_COPY_INP_TMP.Dispose();
                        hv_ColEnd_V_COPY_INP_TMP = new HTuple(hv_ColEnd_V0);
                    }


                    //竖边向左平移*
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourV.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourV, hv_RowEnd_H_COPY_INP_TMP.TupleConcat(
                                hv_RowBegin_V_COPY_INP_TMP), ((hv_ColEnd_V_COPY_INP_TMP - hv_j)).TupleConcat(
                                hv_ColBegin_V_COPY_INP_TMP - hv_j));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_V_COPY_INP_TMP,
                                hv_ColBegin_V_COPY_INP_TMP - hv_j, hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP - hv_j,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }

                        }

                    }

                    //挑选Rows最大值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_VR.Dispose();
                        HOperatorSet.TupleMin(hv_Rows, out hv_VR);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Rows, hv_VR, out hv_Index);
                        hv_VC.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_VC = hv_Cols.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_VR = new HTuple(hv_VR);
                            hv_VR.Dispose();
                            hv_VR = ExpTmpLocalVar_VR;
                        }
                    }
                    else
                    {
                        hv_VC.Dispose();
                        hv_VC = 0;
                        hv_VR.Dispose();
                        hv_VR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_VR, hv_VC, hv_RowBegin_V_COPY_INP_TMP, hv_ColBegin_V_COPY_INP_TMP,
                            hv_RowEnd_V_COPY_INP_TMP, hv_ColEnd_V_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_VR.Dispose();
                        hv_VR = ExpTmpOutVar_0;
                        hv_VC.Dispose();
                        hv_VC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 0; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_V.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_V = (hv_RowEnd_V_COPY_INP_TMP - hv_RowBegin_V_COPY_INP_TMP) / ((hv_ColEnd_V_COPY_INP_TMP - hv_ColBegin_V_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BV.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BV = hv_RowEnd_V_COPY_INP_TMP - (hv_K_V * hv_ColEnd_V_COPY_INP_TMP);
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = hv_VR + hv_i;
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = (((hv_R1 - hv_K_BV) / (hv_K_V + 0.00001))).TupleFloor()
                                ;
                        }
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_VC.Dispose();
                            hv_VC = new HTuple(hv_C1);
                            hv_VR.Dispose();
                            hv_VR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleV.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleV, hv_VR, hv_VC, 0.5);
                    //斜边和长横边的交点*
                    //横边向下平移*
                    hv_Rows.Dispose();
                    hv_Rows = new HTuple();
                    hv_Cols.Dispose();
                    hv_Cols = new HTuple();
                    for (hv_j = 1; (int)hv_j <= 10; hv_j = (int)hv_j + 1)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            ho_ContourH1.Dispose();
                            HOperatorSet.GenContourPolygonXld(out ho_ContourH1, ((hv_RowEnd_H_COPY_INP_TMP + hv_j)).TupleConcat(
                                hv_RowBegin_H_COPY_INP_TMP + hv_j), hv_ColEnd_H_COPY_INP_TMP.TupleConcat(
                                hv_ColBegin_H_COPY_INP_TMP));
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R.Dispose(); hv_C.Dispose(); hv_IsOverlapping.Dispose();
                            HOperatorSet.IntersectionLineContourXld(ho_Contour, hv_RowBegin_H_COPY_INP_TMP + hv_j,
                                hv_ColBegin_H_COPY_INP_TMP, hv_RowEnd_H_COPY_INP_TMP + hv_j, hv_ColEnd_H_COPY_INP_TMP,
                                out hv_R, out hv_C, out hv_IsOverlapping);
                        }
                        if ((int)(new HTuple((new HTuple(hv_R.TupleLength())).TupleGreater(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Rows = hv_Rows.TupleConcat(
                                        hv_R);
                                    hv_Rows.Dispose();
                                    hv_Rows = ExpTmpLocalVar_Rows;
                                }
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Cols = hv_Cols.TupleConcat(
                                        hv_C);
                                    hv_Cols.Dispose();
                                    hv_Cols = ExpTmpLocalVar_Cols;
                                }
                            }
                        }

                    }

                    //挑选Col最小值*
                    if ((int)(new HTuple((new HTuple(hv_Rows.TupleLength())).TupleGreater(0))) != 0)
                    {
                        hv_HC.Dispose();
                        HOperatorSet.TupleMax(hv_Cols, out hv_HC);
                        hv_Index.Dispose();
                        HOperatorSet.TupleFindFirst(hv_Cols, hv_HC, out hv_Index);
                        hv_HR.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_HR = hv_Rows.TupleSelect(
                                hv_Index);
                        }
                        {
                            HTuple
                              ExpTmpLocalVar_HC = new HTuple(hv_HC);
                            hv_HC.Dispose();
                            hv_HC = ExpTmpLocalVar_HC;
                        }
                    }
                    else
                    {
                        hv_HC.Dispose();
                        hv_HC = 0;
                        hv_HR.Dispose();
                        hv_HR = 0;
                    }
                    {
                        HTuple ExpTmpOutVar_0; HTuple ExpTmpOutVar_1;
                        HOperatorSet.ProjectionPl(hv_HR, hv_HC, hv_RowBegin_H_COPY_INP_TMP, hv_ColBegin_H_COPY_INP_TMP,
                            hv_RowEnd_H_COPY_INP_TMP, hv_ColEnd_H_COPY_INP_TMP, out ExpTmpOutVar_0,
                            out ExpTmpOutVar_1);
                        hv_HR.Dispose();
                        hv_HR = ExpTmpOutVar_0;
                        hv_HC.Dispose();
                        hv_HC = ExpTmpOutVar_1;
                    }
                    hv_Dists.Dispose();
                    hv_Dists = new HTuple();
                    for (hv_i = 0; (int)hv_i <= 50; hv_i = (int)hv_i + 1)
                    {
                        hv_K_H.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_H = (hv_RowEnd_H_COPY_INP_TMP - hv_RowBegin_H_COPY_INP_TMP) / ((hv_ColEnd_H_COPY_INP_TMP - hv_ColBegin_H_COPY_INP_TMP) + 0.0001);
                        }
                        hv_K_BH.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_K_BH = hv_RowEnd_H_COPY_INP_TMP - (hv_K_H * hv_ColEnd_H_COPY_INP_TMP);
                        }
                        hv_C1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C1 = hv_HC - hv_i;
                        }
                        hv_R1.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R1 = (((hv_C1 * hv_K_H) + hv_K_BH)).TupleCeil()
                                ;
                        }
                        hv_C.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_C = hv_HC - hv_i;
                        }
                        hv_R.Dispose();
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            hv_R = (hv_C1 * hv_K_H) + hv_K_BH;
                        }
                        if ((int)(new HTuple(((hv_R - (hv_R.TupleRound()))).TupleLess(0))) != 0)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleRound()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }
                        }
                        else
                        {

                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_R = hv_R.TupleFloor()
                                        ;
                                    hv_R.Dispose();
                                    hv_R = ExpTmpLocalVar_R;
                                }
                            }

                        }
                        hv_Grayval0.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R, hv_C, out hv_Grayval0);
                        hv_Grayval.Dispose();
                        HOperatorSet.GetGrayval(ho_Image, hv_R1, hv_C1, out hv_Grayval);
                        ho_Circle1.Dispose();
                        HOperatorSet.GenCircle(out ho_Circle1, hv_R1, hv_C1, 0.5);
                        //该点是否靠近轮廓*
                        for (hv_j = 0; (int)hv_j <= (int)((new HTuple(hv_Rows.TupleLength())) - 1); hv_j = (int)hv_j + 1)
                        {
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                hv_Dist.Dispose();
                                HOperatorSet.DistancePp(hv_R1, hv_C1, hv_Rows.TupleSelect(hv_j), hv_Cols.TupleSelect(
                                    hv_j), out hv_Dist);
                            }
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Dists = hv_Dists.TupleConcat(
                                        hv_Dist);
                                    hv_Dists.Dispose();
                                    hv_Dists = ExpTmpLocalVar_Dists;
                                }
                            }
                        }
                        hv_Min.Dispose();
                        HOperatorSet.TupleMin(hv_Dists, out hv_Min);
                        if ((int)((new HTuple(hv_Grayval.TupleLess(hv_JD_Gray))).TupleAnd(new HTuple(hv_Min.TupleLess(
                            hv_JD_Dist)))) != 0)
                        {
                            hv_HC.Dispose();
                            hv_HC = new HTuple(hv_C1);
                            hv_HR.Dispose();
                            hv_HR = new HTuple(hv_R1);
                            break;
                        }
                    }
                    ho_CircleH.Dispose();
                    HOperatorSet.GenCircle(out ho_CircleH, hv_HR, hv_HC, 0.5);


                }
            }
            catch (Exception)
            {

            }

            ho_DupImage.Dispose();
            ho_Circle.Dispose();
            ho_Contours.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Region.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_ObjectSelected.Dispose();
            ho_Contour.Dispose();
            ho_RegionFillUp.Dispose();
            ho_Rectangle1.Dispose();
            ho_Contour1.Dispose();
            ho_RegionDifference.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_Rectangle2.Dispose();
            ho_Contours1.Dispose();
            ho_ContourV.Dispose();
            ho_ContourH.Dispose();
            ho_CircleV.Dispose();
            ho_ContourH1.Dispose();
            ho_Circle1.Dispose();
            ho_CircleH.Dispose();

            hv_ColBegin_H_COPY_INP_TMP.Dispose();
            hv_ColBegin_V_COPY_INP_TMP.Dispose();
            hv_ColEnd_H_COPY_INP_TMP.Dispose();
            hv_ColEnd_V_COPY_INP_TMP.Dispose();
            hv_RowBegin_H_COPY_INP_TMP.Dispose();
            hv_RowBegin_V_COPY_INP_TMP.Dispose();
            hv_RowEnd_H_COPY_INP_TMP.Dispose();
            hv_RowEnd_V_COPY_INP_TMP.Dispose();
            hv_Pixel.Dispose();
            hv_JD_Gray.Dispose();
            hv_JD_Dist.Dispose();
            hv_Radius_RU.Dispose();
            hv_VH_R.Dispose();
            hv_VH_C.Dispose();
            hv_Ra.Dispose();
            hv_Dist_H.Dispose();
            hv_Dist_W.Dispose();
            hv_RowBegin_H0.Dispose();
            hv_ColBegin_H0.Dispose();
            hv_RowEnd_H0.Dispose();
            hv_ColEnd_H0.Dispose();
            hv_RowBegin_V0.Dispose();
            hv_ColBegin_V0.Dispose();
            hv_RowEnd_V0.Dispose();
            hv_ColEnd_V0.Dispose();
            hv_AngleH.Dispose();
            hv_AngleV.Dispose();
            hv_Angle.Dispose();
            hv_Angle_Sub.Dispose();
            hv_Width.Dispose();
            hv_Height.Dispose();
            hv_Row.Dispose();
            hv_Column.Dispose();
            hv_IsParallel.Dispose();
            hv_UsedThreshold.Dispose();
            hv_Area.Dispose();
            hv_Max.Dispose();
            hv_Index.Dispose();
            hv_Mean.Dispose();
            hv_Deviation.Dispose();
            hv_Row1.Dispose();
            hv_Column1.Dispose();
            hv_Row2.Dispose();
            hv_Column2.Dispose();
            hv_Row11.Dispose();
            hv_Column11.Dispose();
            hv_Row21.Dispose();
            hv_Column21.Dispose();
            hv_Col.Dispose();
            hv_Phi.Dispose();
            hv_Length2.Dispose();
            hv_Length1.Dispose();
            hv_a.Dispose();
            hv_Rows.Dispose();
            hv_Cols.Dispose();
            hv_j.Dispose();
            hv_R.Dispose();
            hv_C.Dispose();
            hv_IsOverlapping.Dispose();
            hv_Dists.Dispose();
            hv_i.Dispose();
            hv_K_V.Dispose();
            hv_K_BV.Dispose();
            hv_R1.Dispose();
            hv_C1.Dispose();
            hv_Grayval.Dispose();
            hv_Dist.Dispose();
            hv_Min.Dispose();
            hv_K_H.Dispose();
            hv_K_BH.Dispose();
            hv_Grayval0.Dispose();

            return;
        }

        public static void rake_edge(HObject ho_Image, HTuple hv_CenterRow, HTuple hv_CenterCol,
      HTuple hv_Phi, HTuple hv_Length1, HTuple hv_Length2, HTuple hv_Step, HTuple hv_Sigma,
      HTuple hv_Threshold, HTuple hv_Transition, HTuple hv_Select, HTuple hv_ShowSearchArea,
      HTuple hv_ShowSearchLine, HTuple hv_ShowResultPoints, HTuple hv_R1, HTuple hv_C1,
      out HTuple hv_RowBegin, out HTuple hv_ColBegin, out HTuple hv_RowEnd, out HTuple hv_ColEnd)
        {




            // Local iconic variables 

            HObject ho_Arrow = null, ho_Rectangle = null, ho_Rectangle1 = null;
            HObject ho_Contour = null;

            // Local control variables 

            HTuple hv_RowLine = new HTuple(), hv_ColLine = new HTuple();
            HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
            HTuple hv_Index = new HTuple(), hv_MeasureHandle1 = new HTuple();
            HTuple hv_RowEdge = new HTuple(), hv_ColumnEdge = new HTuple();
            HTuple hv_Amplitude = new HTuple(), hv_Distance = new HTuple();
            HTuple hv_Length = new HTuple(), hv_RL = new HTuple();
            HTuple hv_CL = new HTuple(), hv_Count = new HTuple(), hv_RowsNew = new HTuple();
            HTuple hv_ColsNew = new HTuple(), hv_M_Row1 = new HTuple();
            HTuple hv_M_Col1 = new HTuple(), hv_D_Row1 = new HTuple();
            HTuple hv_D_Col1 = new HTuple(), hv_i = new HTuple(), hv_Nr = new HTuple();
            HTuple hv_Nc = new HTuple(), hv_Dist = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            HOperatorSet.GenEmptyObj(out ho_Rectangle);
            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_Contour);
            hv_RowBegin = new HTuple();
            hv_ColBegin = new HTuple();
            hv_RowEnd = new HTuple();
            hv_ColEnd = new HTuple();
            //*************************输入
            //Image:输入图像
            //CenterRow:输入矩形框的行中心
            //CenterCol:输入矩形框的列中心
            //Phi:输入矩形框的角度
            //Length1:输入矩形框的宽度
            //Length2:输入矩形框的高度
            //Step:扫描间隔
            //Sigma:高期平滑度
            //Threshold:最小边缘过渡
            //Transition:边缘提取方式,'negative'从白到黑,'positive'从黑到白,'all'都可以
            //Select:选取点方式,'first'第一个,'last'最后一个,'all'两者都有
            //ShowSearchArea:是否显示搜索框
            //ShowSearchLine:是否显示搜索线
            //ShowResultPoints:是否显示结果点

            //************************输出
            //RowBegin:边的起始行
            //ColBegin:边的起始列
            //RowEnd:边的终点行
            //ColEnd:边的终点列

            //是否显示搜索区域
            if ((int)(new HTuple(hv_ShowSearchArea.TupleEqual("TRUE"))) != 0)
            {
                //在搜索框外显示角度指示箭头
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    ho_Arrow.Dispose();
                    gen_arrow_contour_xld(out ho_Arrow, hv_CenterRow + ((hv_Phi.TupleSin()) * (hv_Length1 + 20)),
                        hv_CenterCol - ((hv_Phi.TupleCos()) * (hv_Length1 + 20)), hv_CenterRow + ((hv_Phi.TupleSin()
                        ) * hv_Length1), hv_CenterCol - ((hv_Phi.TupleCos()) * hv_Length1), 10, 10);
                }
                //生成搜索框
                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_CenterRow, hv_CenterCol, hv_Phi,
                    hv_Length1, hv_Length2);
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetColor(HDevWindowStack.GetActive(), "green");
                }
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 2);
                }
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.DispObj(ho_Arrow, HDevWindowStack.GetActive());
                }
                if (HDevWindowStack.IsOpen())
                {
                    HOperatorSet.DispObj(ho_Rectangle, HDevWindowStack.GetActive());
                }
            }

            if (HDevWindowStack.IsOpen())
            {
                HOperatorSet.SetLineWidth(HDevWindowStack.GetActive(), 1);
            }
            //初始化结果点的行列
            hv_RowLine.Dispose();
            hv_RowLine = new HTuple();
            hv_ColLine.Dispose();
            hv_ColLine = new HTuple();
            hv_Width.Dispose(); hv_Height.Dispose();
            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);

            //循环扫描点
            HTuple end_val41 = (hv_Length2 * 2) / hv_Step;
            HTuple step_val41 = 1;
            for (hv_Index = 0; hv_Index.Continue(end_val41, step_val41); hv_Index = hv_Index.TupleAdd(step_val41))
            {
                //生成测量矩形,宽度为0,即为一条直线
                using (HDevDisposeHelper dh = new HDevDisposeHelper())
                {
                    hv_MeasureHandle1.Dispose();
                    HOperatorSet.GenMeasureRectangle2(hv_CenterRow - ((hv_Phi.TupleCos()) * (hv_Length2 - (hv_Step * hv_Index))),
                        hv_CenterCol - ((hv_Phi.TupleSin()) * (hv_Length2 - (hv_Step * hv_Index))), hv_Phi,
                        hv_Length1, 0, hv_Width, hv_Height, "nearest_neighbor", out hv_MeasureHandle1);
                }
                //是否显示搜索线
                if ((int)(new HTuple(hv_ShowSearchLine.TupleEqual("TRUE"))) != 0)
                {
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_Rectangle1.Dispose();
                        HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_CenterRow - ((hv_Phi.TupleCos()
                            ) * (hv_Length2 - (hv_Step * hv_Index))), hv_CenterCol - ((hv_Phi.TupleSin()) * (hv_Length2 - (hv_Step * hv_Index))),
                            hv_Phi, hv_Length1, 0);
                    }
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.SetColor(HDevWindowStack.GetActive(), "blue");
                    }
                    if (HDevWindowStack.IsOpen())
                    {
                        HOperatorSet.DispObj(ho_Rectangle1, HDevWindowStack.GetActive());
                    }
                }

                //测量点
                hv_RowEdge.Dispose(); hv_ColumnEdge.Dispose(); hv_Amplitude.Dispose(); hv_Distance.Dispose();
                HOperatorSet.MeasurePos(ho_Image, hv_MeasureHandle1, hv_Sigma, hv_Threshold,
                    hv_Transition, hv_Select, out hv_RowEdge, out hv_ColumnEdge, out hv_Amplitude,
                    out hv_Distance);
                HOperatorSet.CloseMeasure(hv_MeasureHandle1);
                //是否显示结果点
                if ((int)(new HTuple(hv_ShowResultPoints.TupleEqual("TRUE"))) != 0)
                {
                    hv_Length.Dispose();
                    HOperatorSet.TupleLength(hv_RowEdge, out hv_Length);
                    if ((int)(new HTuple(hv_Length.TupleGreater(0))) != 0)
                    {
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            {
                                HTuple
                                  ExpTmpLocalVar_RowLine = hv_RowLine.TupleConcat(
                                    hv_RowEdge);
                                hv_RowLine.Dispose();
                                hv_RowLine = ExpTmpLocalVar_RowLine;
                            }
                        }
                        using (HDevDisposeHelper dh = new HDevDisposeHelper())
                        {
                            {
                                HTuple
                                  ExpTmpLocalVar_ColLine = hv_ColLine.TupleConcat(
                                    hv_ColumnEdge);
                                hv_ColLine.Dispose();
                                hv_ColLine = ExpTmpLocalVar_ColLine;
                            }
                        }
                        //生成十字架


                    }
                }

            }
            //计算结果点的行列个数
            hv_RL.Dispose();
            HOperatorSet.TupleLength(hv_RowLine, out hv_RL);
            hv_CL.Dispose();
            HOperatorSet.TupleLength(hv_RowLine, out hv_CL);

            //*剔除远离点**
            hv_Count.Dispose();
            hv_Count = 0;
            hv_RowsNew.Dispose();
            hv_RowsNew = new HTuple();
            hv_ColsNew.Dispose();
            hv_ColsNew = new HTuple();
            if ((int)((new HTuple(hv_RL.TupleGreater(3))).TupleAnd(new HTuple(hv_CL.TupleGreater(
                3)))) != 0)
            {

                //* 剔除远离点 **
                hv_M_Row1.Dispose();
                HOperatorSet.TupleMean(hv_RowLine, out hv_M_Row1);
                hv_M_Col1.Dispose();
                HOperatorSet.TupleMean(hv_ColLine, out hv_M_Col1);
                hv_D_Row1.Dispose();
                HOperatorSet.TupleDeviation(hv_RowLine, out hv_D_Row1);
                hv_D_Col1.Dispose();
                HOperatorSet.TupleDeviation(hv_ColLine, out hv_D_Col1);
                if ((int)(hv_R1) != 0)
                {
                    for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_ColLine.TupleLength())) - 1); hv_i = (int)hv_i + 1)
                    {
                        if ((int)(new HTuple(((((hv_RowLine.TupleSelect(hv_i)) - hv_M_Row1) * ((hv_RowLine.TupleSelect(
                            hv_i)) - hv_M_Row1))).TupleLess(hv_D_Row1 * hv_D_Row1))) != 0)
                        {

                            if (hv_RowsNew == null)
                                hv_RowsNew = new HTuple();
                            hv_RowsNew[hv_Count] = hv_RowLine.TupleSelect(hv_i);
                            if (hv_ColsNew == null)
                                hv_ColsNew = new HTuple();
                            hv_ColsNew[hv_Count] = hv_ColLine.TupleSelect(hv_i);
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Count = hv_Count + 1;
                                    hv_Count.Dispose();
                                    hv_Count = ExpTmpLocalVar_Count;
                                }
                            }

                        }
                    }
                }
                if ((int)(hv_C1) != 0)
                {
                    for (hv_i = 0; (int)hv_i <= (int)((new HTuple(hv_ColLine.TupleLength())) - 1); hv_i = (int)hv_i + 1)
                    {
                        if ((int)(new HTuple(((((hv_ColLine.TupleSelect(hv_i)) - hv_M_Col1) * ((hv_ColLine.TupleSelect(
                            hv_i)) - hv_M_Col1))).TupleLess(hv_D_Col1 * hv_D_Col1))) != 0)
                        {

                            if (hv_RowsNew == null)
                                hv_RowsNew = new HTuple();
                            hv_RowsNew[hv_Count] = hv_RowLine.TupleSelect(hv_i);
                            if (hv_ColsNew == null)
                                hv_ColsNew = new HTuple();
                            hv_ColsNew[hv_Count] = hv_ColLine.TupleSelect(hv_i);
                            using (HDevDisposeHelper dh = new HDevDisposeHelper())
                            {
                                {
                                    HTuple
                                      ExpTmpLocalVar_Count = hv_Count + 1;
                                    hv_Count.Dispose();
                                    hv_Count = ExpTmpLocalVar_Count;
                                }
                            }

                        }
                    }
                }
                //生成Contour
                //gen_contour_polygon_xld (Contour, RowsNew, ColsNew)
                ho_Contour.Dispose();
                HOperatorSet.GenContourPolygonXld(out ho_Contour, hv_RowLine, hv_ColLine);

                //拟合直线,参数可以更改或改成接口
                hv_RowBegin.Dispose(); hv_ColBegin.Dispose(); hv_RowEnd.Dispose(); hv_ColEnd.Dispose(); hv_Nr.Dispose(); hv_Nc.Dispose(); hv_Dist.Dispose();
                HOperatorSet.FitLineContourXld(ho_Contour, "tukey", -1, 0, 5, 2, out hv_RowBegin,
                    out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc, out hv_Dist);
                //结果点的行个数或列个数>=2拟合,防止报错
            }
            else
            {
                //置为-1,防止输出时画直线报错
                hv_RowBegin.Dispose();
                hv_RowBegin = -1;
                hv_ColBegin.Dispose();
                hv_ColBegin = -1;
                hv_RowEnd.Dispose();
                hv_RowEnd = -1;
                hv_ColEnd.Dispose();
                hv_ColEnd = -1;
            }



            ho_Arrow.Dispose();
            ho_Rectangle.Dispose();
            ho_Rectangle1.Dispose();
            ho_Contour.Dispose();

            hv_RowLine.Dispose();
            hv_ColLine.Dispose();
            hv_Width.Dispose();
            hv_Height.Dispose();
            hv_Index.Dispose();
            hv_MeasureHandle1.Dispose();
            hv_RowEdge.Dispose();
            hv_ColumnEdge.Dispose();
            hv_Amplitude.Dispose();
            hv_Distance.Dispose();
            hv_Length.Dispose();
            hv_RL.Dispose();
            hv_CL.Dispose();
            hv_Count.Dispose();
            hv_RowsNew.Dispose();
            hv_ColsNew.Dispose();
            hv_M_Row1.Dispose();
            hv_M_Col1.Dispose();
            hv_D_Row1.Dispose();
            hv_D_Col1.Dispose();
            hv_i.Dispose();
            hv_Nr.Dispose();
            hv_Nc.Dispose();
            hv_Dist.Dispose();

            return;
        }

        public static void gen_arrow_contour_xld(out HObject ho_Arrow, HTuple hv_Row1, HTuple hv_Column1,
      HTuple hv_Row2, HTuple hv_Column2, HTuple hv_HeadLength, HTuple hv_HeadWidth)
        {



            // Stack for temporary objects 
            HObject[] OTemp = new HObject[20];

            // Local iconic variables 

            HObject ho_TempArrow = null;

            // Local control variables 

            HTuple hv_Length = new HTuple(), hv_ZeroLengthIndices = new HTuple();
            HTuple hv_DR = new HTuple(), hv_DC = new HTuple(), hv_HalfHeadWidth = new HTuple();
            HTuple hv_RowP1 = new HTuple(), hv_ColP1 = new HTuple();
            HTuple hv_RowP2 = new HTuple(), hv_ColP2 = new HTuple();
            HTuple hv_Index = new HTuple();
            // Initialize local and output iconic variables 
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            HOperatorSet.GenEmptyObj(out ho_TempArrow);
            //This procedure generates arrow shaped XLD contours,
            //pointing from (Row1, Column1) to (Row2, Column2).
            //If starting and end point are identical, a contour consisting
            //of a single point is returned.
            //
            //input parameteres:
            //Row1, Column1: Coordinates of the arrows' starting points
            //Row2, Column2: Coordinates of the arrows' end points
            //HeadLength, HeadWidth: Size of the arrow heads in pixels
            //
            //output parameter:
            //Arrow: The resulting XLD contour
            //
            //The input tuples Row1, Column1, Row2, and Column2 have to be of
            //the same length.
            //HeadLength and HeadWidth either have to be of the same length as
            //Row1, Column1, Row2, and Column2 or have to be a single element.
            //If one of the above restrictions is violated, an error will occur.
            //
            //
            //Init
            ho_Arrow.Dispose();
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            //
            //Calculate the arrow length
            hv_Length.Dispose();
            HOperatorSet.DistancePp(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Length);
            //
            //Mark arrows with identical start and end point
            //(set Length to -1 to avoid division-by-zero exception)
            hv_ZeroLengthIndices.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ZeroLengthIndices = hv_Length.TupleFind(
                    0);
            }
            if ((int)(new HTuple(hv_ZeroLengthIndices.TupleNotEqual(-1))) != 0)
            {
                if (hv_Length == null)
                    hv_Length = new HTuple();
                hv_Length[hv_ZeroLengthIndices] = -1;
            }
            //
            //Calculate auxiliary variables.
            hv_DR.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_DR = (1.0 * (hv_Row2 - hv_Row1)) / hv_Length;
            }
            hv_DC.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_DC = (1.0 * (hv_Column2 - hv_Column1)) / hv_Length;
            }
            hv_HalfHeadWidth.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_HalfHeadWidth = hv_HeadWidth / 2.0;
            }
            //
            //Calculate end points of the arrow head.
            hv_RowP1.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_RowP1 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) + (hv_HalfHeadWidth * hv_DC);
            }
            hv_ColP1.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ColP1 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) - (hv_HalfHeadWidth * hv_DR);
            }
            hv_RowP2.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_RowP2 = (hv_Row1 + ((hv_Length - hv_HeadLength) * hv_DR)) - (hv_HalfHeadWidth * hv_DC);
            }
            hv_ColP2.Dispose();
            using (HDevDisposeHelper dh = new HDevDisposeHelper())
            {
                hv_ColP2 = (hv_Column1 + ((hv_Length - hv_HeadLength) * hv_DC)) + (hv_HalfHeadWidth * hv_DR);
            }
            //
            //Finally create output XLD contour for each input point pair
            for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_Length.TupleLength())) - 1); hv_Index = (int)hv_Index + 1)
            {
                if ((int)(new HTuple(((hv_Length.TupleSelect(hv_Index))).TupleEqual(-1))) != 0)
                {
                    //Create_ single points for arrows with identical start and end point
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_TempArrow.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_TempArrow, hv_Row1.TupleSelect(hv_Index),
                            hv_Column1.TupleSelect(hv_Index));
                    }
                }
                else
                {
                    //Create arrow contour
                    using (HDevDisposeHelper dh = new HDevDisposeHelper())
                    {
                        ho_TempArrow.Dispose();
                        HOperatorSet.GenContourPolygonXld(out ho_TempArrow, ((((((((((hv_Row1.TupleSelect(
                            hv_Index))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat(
                            hv_RowP1.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)))).TupleConcat(
                            hv_RowP2.TupleSelect(hv_Index)))).TupleConcat(hv_Row2.TupleSelect(hv_Index)),
                            ((((((((((hv_Column1.TupleSelect(hv_Index))).TupleConcat(hv_Column2.TupleSelect(
                            hv_Index)))).TupleConcat(hv_ColP1.TupleSelect(hv_Index)))).TupleConcat(
                            hv_Column2.TupleSelect(hv_Index)))).TupleConcat(hv_ColP2.TupleSelect(
                            hv_Index)))).TupleConcat(hv_Column2.TupleSelect(hv_Index)));
                    }
                }
                {
                    HObject ExpTmpOutVar_0;
                    HOperatorSet.ConcatObj(ho_Arrow, ho_TempArrow, out ExpTmpOutVar_0);
                    ho_Arrow.Dispose();
                    ho_Arrow = ExpTmpOutVar_0;
                }
            }
            ho_TempArrow.Dispose();

            hv_Length.Dispose();
            hv_ZeroLengthIndices.Dispose();
            hv_DR.Dispose();
            hv_DC.Dispose();
            hv_HalfHeadWidth.Dispose();
            hv_RowP1.Dispose();
            hv_ColP1.Dispose();
            hv_RowP2.Dispose();
            hv_ColP2.Dispose();
            hv_Index.Dispose();

            return;
        }

        #endregion


    }
}
